You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added a very descriptive title to this question.
I searched the LangChain documentation with the integrated search.
I used the GitHub search to find a similar question and didn't find it.
Commit to Help
I commit to help with one of those options 👆
Example Code
`
fromlangchain.memoryimportConversationBufferMemorydefstart_chat: Update, context: CallbackContext) ->None:
...
vectorstore=Chroma(
embedding_function=embed_model,
persist_directory="chroma_db_dir",
collection_name="my_collection"
)
retriever=vectorstore.as_retriever(search_kwargs={'k': 4})
custom_prompt_template=""" Answer using the provided context and the conversation history. If the context does not help to answer the question, indicate that you do not have enough information Context: {context} History: {history} Question: {question} [Respond in Spanish] """prompt=PromptTemplate(template=custom_prompt_template, input_variables=['context','history','question',])
memory=ConversationBufferMemory(return_messages=True, input_key="query",output_key="result",memory_key="history")
qa=RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
memory=memory, # Le pasa la memoria del chat en el promptretriever=retriever,
return_source_documents=False,
chain_type_kwargs={"prompt": prompt},
)
context.user_data['memory'] =memorydefresponder_pregunta(update: Update, context: CallbackContext) ->None:
....
....
question=update.message.textmemory=context.user_data.get('memory')
memory_variables=memory.load_memory_variables({})
answer=qa.invoke({"query": pregunta,"history": memory_variables})
update.message.reply_text(answer['result'])
`
Description
I'm trying to implement chat memory using ConversationBufferMemory, and use the chat history in the prompt to provide context in the awnser of the chat questions
the way I implemented the memory is storing correctly the messages and the answers.
The issue is that the cant pass it to the propt.
I'm trying by using an input_variable History: {history} but have the error : (ValueError: Missing some input keys: {'history'}) even though I'm passing explicity the history: answer= qa.invoke({"query": pregunta,"history": memory_variables})
cold you help me? whats wrong or how this should be done ?
System Info
windows 11
langchain_ollama 0.3.3
LangChain 0.3.26
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I'm trying to implement chat memory using ConversationBufferMemory, and use the chat history in the prompt to provide context in the awnser of the chat questions
the way I implemented the memory is storing correctly the messages and the answers.
The issue is that the cant pass it to the propt.
I'm trying by using an input_variable History: {history} but have the error : (ValueError: Missing some input keys: {'history'}) even though I'm passing explicity the history: answer= qa.invoke({"query": pregunta,"history": memory_variables})
cold you help me? whats wrong or how this should be done ?
System Info
windows 11
langchain_ollama 0.3.3
LangChain 0.3.26
Beta Was this translation helpful? Give feedback.
All reactions