mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
ollama-python equivalent of /clear and context summarization in a chat #100
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @JiahuiKChen on GitHub (Jun 17, 2024).
When using
ollama run <model>, there's a/clearcommand to "clear session context".How can this be done in the ollama-python library? I can't figure out if it's possible when looking at
client.py.My use case is that I want to chat with the same model in a script but clear the context occasionally.
I'm also interested in how to summarize older conversations to enable longer history with less context, mentioned in this example.
Would I have to explicitly ask the model to summarize its context so far, clear the context, then prompt the model with the saved summary -- or is there a built-in way for the model to summarize its context so far and retain the summary, while clearing the rest of its context?
@JICA98 commented on GitHub (Jun 20, 2024):
+1
@militu commented on GitHub (Jun 23, 2024):
For the first question, it seems natively handled, look here https://github.com/ollama/ollama/issues/4564
@pdevine commented on GitHub (Jun 26, 2024):
@JiahuiKChen You have to handle this yourself in the client. You can just empty the
messageslist, which is effectively what/cleardoes. You'll have to repopulate the system message again (although we have been looking at doing this automatically in the future).You definitely can ask the LLM to summarize the current conversation and then substitute that into the messages if you want the LLM to not "lose its brain". We haven't added that capability yet into Ollama.
I'll go ahead and close the issue.