-
I'm trying to add more variables to my Retrieval QA Prompt Template, but there is no way to make it work template = """You are a human assist that is expert with our app.
Always say "Best regards" at the end of the answer, and "Thanks for your request, at the beginning.
{context}
App: {app}
At the end of your sentence return the used app"""
template.format(app = myapp, context = "")
QA_CHAIN_PROMPT = PromptTemplate.from_template(template)
qa_chain = RetrievalQA.from_chain_type(llm,retriever=vectorStore.as_retriever(search_kwargs={'k':8}), chain_type_kwargs={"prompt": QA_CHAIN_PROMPT}, return_source_documents=True)
result = qa_chain({"query": myquery, "app": myapp})
print(qa_chain) What is exactly failing in my code? I can't make it work. Also, it forces me to give a value to the context, I dont know if theres any impact for having the context empty. This is the error that appears: I also tried giving the value manually instead that from a variable but nothing worked |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 12 replies
-
🤖 Thanks for your request, The error message you're seeing, To fix this, you need to modify both the template = """You are a human assist that is expert with our app.
Always say "Best regards" at the end of the answer, and "Thanks for your request, at the beginning.
{context}
App: {app}
At the end of your sentence return the used app"""
QA_CHAIN_PROMPT = PromptTemplate(
input_variables=["app", "context"],
template=template,
)
qa_chain = RetrievalQA.from_chain_type(llm,retriever=vectorStore.as_retriever(search_kwargs={'k':8}), chain_type_kwargs={"prompt": QA_CHAIN_PROMPT}, return_source_documents=True)
result = qa_chain({"query": myquery, "app": myapp})
print(qa_chain) In this code, As for the I hope this helps! Let me know if you have any other questions. Best regards, Sources
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. |
Beta Was this translation helpful? Give feedback.
-
Did you find a solution? |
Beta Was this translation helpful? Give feedback.
-
The original code has a bug in it -- After formatting the value needs to be assigned to a variable myapp = 'hello'
context = 'meow'
template = """You are a human assist that is expert with our app.
Always say "Best regards" at the end of the answer, and "Thanks for your request, at the beginning.
{context}
App: {app}
At the end of your sentence return the used app"""
template.format(app=myapp, context=context)
print(template)
print("Correct")
template = template.format(app=myapp, context=context)
print(template)
QA_CHAIN_PROMPT = PromptTemplate.from_template(template)
QA_CHAIN_PROMPT.invoke({}) |
Beta Was this translation helpful? Give feedback.
-
Is there a fix available for this from Langchain's codebase? |
Beta Was this translation helpful? Give feedback.
The original code has a bug in it -- After formatting the value needs to be assigned to a variable