-
Notifications
You must be signed in to change notification settings - Fork 13.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue: Not getting good chat results on enabling Coversation Memory in langchain #7921
Comments
Answer generated by a 🤖 AnswerI understand that you're experiencing some issues with the Conversation Memory feature in LangChain. Specifically, you've noticed that the quality of the bot's responses decreases after the first question, and that LangChain seems to be adding additional conversations to the chat history. You've tried using both The problem you're encountering might be related to how the The One potential solution is to override the Here's an example of how you might do this: def _get_chat_history(chat_history: List[CHAT_TURN_TYPE]) -> str:
buffer = ""
for dialogue_turn in chat_history:
if isinstance(dialogue_turn, BaseMessage):
role_prefix = _ROLE_MAP.get(dialogue_turn.type, f"{dialogue_turn.type}: ")
buffer += f"\n{role_prefix}{dialogue_turn.content}"
elif isinstance(dialogie_turn, tuple):
human = "Human: " + dialogue_turn[0]
ai = "Assistant: " + dialogue_turn[1]
buffer += "\n" + "\n".join([human, ai])
else:
raise ValueError(
f"Unsupported chat history format: {type(dialogue_turn)}."
f" Full chat history: {chat_history} "
)
return buffer Please note that this is just one possible solution, and it may not fully address the issue. If you're still having problems, it would be helpful if you could provide more details about the specific questions that are causing issues and the incorrect responses you're receiving. This information could help us identify if there's a specific problem with how the If you find that this solution works for you and you believe it could benefit other users, we encourage you to make a pull request. If the issue persists, please ensure you're using the latest version of LangChain, as updates often include bug fixes and performance improvements. SourcesThis response is meant to be useful, save you time, and share context. 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. |
Hi, Thanks for the response, it helped me I implemented custom function for get_chat_history to return only chat history, with this response accuracy is imporved, but still I could see for few questions, it is not able to provide answer with continous conversation, it provides answers on re-initilizing the chain. For eg: Why Does Applying Different Weights to a Model Affect the Inference Performance? , Answer while conversing:" Applying different weights can improve or degrade the accuracy of the model" Is it due to stand alone question that it generates? Also some times Bot response also will be set of continous and answes even if I ask single question, Below is an eg Also I tried to use map_reduce instead of stuff type, Iam getting below error , KeyError: 'Could not automatically map gpt-35-turbo to a tokeniser. Please use |
Answer generated by a 🤖 AnswerI understand that you're experiencing a few issues with LangChain. Firstly, you're getting inconsistent responses to the same question depending on whether the chain is reinitialized or not. Secondly, you're receiving multiple answers to a single question. Lastly, you're encountering a KeyError when trying to use
Here's a potential modification to your code: from langchain.tokenizer import TikTok
# Initialize the tokenizer
tokenizer = TikTok()
# Use the tokenizer to encode your question
encoded_question = tokenizer.encode(<question>)
# Pass the encoded question to the chain
result = chain({"question": encoded_question}) Please replace Please note that these are potential solutions based on the information provided and may not completely resolve your issues. If you find these solutions helpful and believe they could benefit other users, we encourage you to make a pull request to update the documentation. This way, you can contribute to the LangChain community and help other users who might encounter similar issues. SourcesThis response is meant to be useful, save you time, and share context. 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. |
Thanks a lot for your response, |
Answer generated by a 🤖 AnswerI understand that you're experiencing a couple of issues with LangChain. Firstly, you're noticing inconsistent responses from the bot in a continuous conversation, and sometimes it provides multiple answers to a single question. Secondly, you're encountering a KeyError when trying to use Let's address these issues one by one. The "ModuleNotFoundError" is occurring because there isn't a module named 'langchain.tokenizer' in the LangChain framework. The import statement Regarding the control over standalone questions that LangChain generates, LangChain doesn't provide explicit control over this. However, you can influence the model's responses by the input messages. For example, you can use a Here's an example: from langchain.schema import (
AIMessage,
HumanMessage,
SystemMessage
)
messages = [
SystemMessage(content="You are a helpful assistant that translates English to French."),
HumanMessage(content="I love programming.")
]
chat(messages) In this case, the AI model will respond with a translation of the sentence in French. This way, you can guide the AI model to provide the desired responses. Please note that this is one potential solution and there might be other ways to address your issue. If you find this solution helpful and believe it's not covered by existing documentation, I encourage you to make a pull request to update the documentation for the benefit of other users. SourcesThis response is meant to be useful, save you time, and share context. 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. |
Hi, Initialize the tokenizertokenizer = TikTok() Use the tokenizer to encode your questionencoded_question = tokenizer.encode() Pass the encoded question to the chainresult = chain({"question": encoded_question}) For that only I got an error ModuleNotFoundError: No module named 'langchain.tokenizer'" So how to encode the question before sending to chain? Can you please send the detailed steps |
Answer generated by a 🤖 AnswerI apologize for the confusion. It seems that there is no To help you further, could you please provide more details about the specific version of LangChain you are using? Additionally, if you have any error logs related to this issue, please share them as well. Lastly, if possible, could you provide the specific question you are trying to encode? With this information, I'll be able to assist you better in finding a solution. This response is meant to be useful, save you time, and share context. 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. |
@dkiran1 What model are you using? |
Hi Devstein, I sam using Azure GPT35 model, Actually I used langchain 0.0.235 version, If I use map_reduce instead of stuff chain, then Iam getting below error , KeyError: 'Could not automatically map gpt-35-turbo to a tokeniser. Please use tiktok.get_encoding to explicitly get the tokeniser you expect.' |
Hi, @dkiran1! I'm Dosu, and I'm here to help the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale. Based on my understanding of the issue, you reported a problem with enabling Conversation Memory in langchain. You mentioned that the bot is adding additional conversations by itself, leading to poor chat results. You implemented a custom function for Before we close this issue, we wanted to check if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days. Thank you for your contribution and we appreciate your understanding! |
Issue you'd like to raise.
Hi,
Here is how i have initilized conversation memory
memory = ConversationSummaryBufferMemory(llm=llm_model,memory_key="chat_history",return_messages=True,max_token_limit=500)
Here is how I have used ConversationalRetrievalChain
chain=ConversationalRetrievalChain.from_llm(llm_model,retriever=vector.as_retriever(search_kwargs={"k": 10}), memory=memory,verbose=True)
I could see that answer for first question will be good, on asking further questions with
result = chain({"question": }) answer from bot is not good for few questions. With verbose enabled I have observed that apart from the actual history langchain is adding few more conversations by itself. Is there a way to supress this(adding additional conversation)
I also tried with ConversationBufferWindowMemory aswell. There also Iam seeing the performance drop. I tried with new langchain version as well "0.0.235", there also Iam seeing the same issue. Could you help me to undersatnd if this is an existing issue or any mistake am I doing while configuring
Suggestion:
No response
The text was updated successfully, but these errors were encountered: