Skip to content
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

Ability to Summarize an LLM Conversation #216

Merged
merged 9 commits into from
Dec 15, 2024
Merged

Conversation

brainlid
Copy link
Owner

@brainlid brainlid commented Dec 15, 2024

Adds LangChain.Chains.SummarizeConversationChain.

The purpose is to allow for long user/assistant conversations while trying to keep the context window and the total number of input tokens under control.

This takes a long LLMChain conversation (with numerous user and assistant back-and-forth messages) and combines the message contents into a single message so an LLM can summarize the conversation up to a certain point.

The summarized result is spliced into the original LLMChain where the system prompt is kept unaltered and some number of messages are removed and replaced with the summarized contents of the conversation. The system prompt used for summarizing can be overridden.

A threshold_count is used to specify the number of message that must be in the chain before the summarizing process is performed. A keep_count value specifies the number of unsummarized messages to keep on the returned chain. This helps with recent message consistency with the LLM.

It is safe to run on an LLMChain with a short number of messages because if the threshold_count is not reached, it returns the original LLMChain without summarizing.

NOTE: A few other fixes found there way into this PR. This includes:

  • Improved error handling
  • The ability to override LangChain.Chains.TextToTitleChain's system prompt.

- fixed LangChainError type spec
- LLMChain.run - raise specific exception when being run without messages
- try/rescue errors in LLMChain.run and return error tuple (fixes spec)
- updated docs with examples
- support full `override_system_prompt` for greater customization
* main:
  Azure test for ChatOpenAI usage
  added documentation for ChatOpenAI use on Azure
  Fix specs and examples (#211)
  Fix content-part encoding and decoding for Google API. (#212)
* main:
  added error type support for Azure token rate limit exceeded
- operates on an LLMChain to shorten and summarize the messages
- changes when the keep_count is 0
@brainlid brainlid merged commit 94980a3 into main Dec 15, 2024
1 check passed
@brainlid brainlid deleted the me-summarize-conversation branch December 15, 2024 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant