langchain icon indicating copy to clipboard operation
langchain copied to clipboard

How can we set a limit for max tokens in ConversationSummaryMemory

Open m-ali-awan opened this issue 2 years ago • 2 comments

Hi all, One major benefit of using Summary method for context in Conversation is to save cost. But with increasing chat iterations, no of token keeps on increasing, significantly. Is there any parameter, by which I can set the max limit of Summary?

m-ali-awan avatar May 03 '23 09:05 m-ali-awan

I think the solution is use ConversationSummaryBufferMemory

from langchain.chains import ConversationChain
conversation_with_summary = ConversationChain(
    llm=llm, 
    # We set a very low max_token_limit for the purposes of testing.
    memory=ConversationSummaryBufferMemory(llm=OpenAI(), max_token_limit=40),
    verbose=True
)
conversation_with_summary.predict(input="Hi, what's up?")

giuice avatar May 03 '23 14:05 giuice

Thanks @giuice

m-ali-awan avatar May 03 '23 14:05 m-ali-awan

Hi, @m-ali-awan! 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.

From what I understand, the issue is about setting a limit for the maximum number of tokens in ConversationSummaryMemory. You asked if there is a parameter available to set this maximum limit. Another user named "giuice" suggested using ConversationSummaryBufferMemory as a solution and even provided an example code snippet. You thanked "giuice" for the suggestion.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.

Thank you for your understanding and contribution to the LangChain project!

dosubot[bot] avatar Sep 06 '23 16:09 dosubot[bot]

How can I put limit in prediction instead of initialisation

celikmustafa89 avatar Nov 21 '23 12:11 celikmustafa89