Closed levalencia closed 4 months ago
🤖
Hello again @levalencia! Nice to see you back in the LangChain repo. I appreciate your thorough detailing of the issue, it really helps to understand the context. I'm diving into the problem you've described and will be back with a comprehensive response soon.
🤖
It seems like you're encountering a KeyError
for 'template' because the PromptTemplate
object is not being initialized correctly. In your code, you're passing the PromptTemplate
object itself as the template, instead of a string.
Here's the corrected part of your code:
PROMPT = PromptTemplate(
template=prompt_template, input_variables=["summaries", "question"]
)
chain = RetrievalQAWithSourcesChain.from_chain_type(llm=llm,
chain_type="stuff",
retriever=retriever,
memory= memory,
chain_type_kwargs={
"prompt": PROMPT,
},
)
In this corrected code, PROMPT
is a PromptTemplate
object that is initialized with prompt_template
(a string) as the template and ["summaries", "question"]
as the input variables. This PROMPT
object is then passed as the prompt
argument when initializing RetrievalQAWithSourcesChain
.
Please note that the PromptTemplate
object expects a string as the template, and this string should contain placeholders for the input variables. In your case, the placeholders are {summaries}
and {question}
.
For more information about the PromptTemplate
object and how it works, you can refer to the PromptTemplate documentation.
If you're still encountering issues after making these changes, please provide more details about the error and I'll be glad to help further.
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
Checked other resources
Example Code
Description
I want to use RetrievalQAWithSourcesChain to generate an answer and the relevant sources from the retriever. However with this code I am getting this error:
. System.Private.CoreLib: Result: Failure Exception: KeyError: 'template'
prompt.py", line 146, in template_is_valid values["template"], values["template_format"]
System Info
langchain==0.1.0 langsmith==0.0.80 langchainhub==0.1.14 langchain-community==0.0.12 openai==1.7.2 azure-identity == 1.13.0 azure-core ==1.28.0
Related Components