Ability to Summarize an LLM Conversation #216
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andassistant
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. Akeep_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:
LangChain.Chains.TextToTitleChain
's system prompt.