How to pass in the system_prompt in a template used by langchain.prompts PromptTemplate.from_template?

26 Views Asked by At

I am trying to run this code but getting an error.

Code:

vector_store_retriever, llm, system_prompt = initialize_components()


def construct_rag_chain():
    full_prompt = PromptTemplate.from_template(
    """
    <s>[INST]{system_prompt}[/INST]</s>
    [INST] Question: {question} Context: {context} Answer: [/INST]
    """
    )
    return (
        {"system_prompt": system_prompt, "context": vector_store_retriever, "question": RunnablePassthrough()}
        | full_prompt
        | llm
        | StrOutputParser()
    )

And I am getting this error:

TypeError: Expected a Runnable, callable or dict.Instead got an unsupported type: <class 'str'>

The system_prompt is just a string that I want to use. It is coming from a .yaml file. How do I insert this string into the prompt? I don't want to hardcode it.

0

There are 0 best solutions below