mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
Persistent chat memory #121
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 @kikoferrer on GitHub (Jul 31, 2024).
I have ollama-python running with a custom ollama model. It works very well except that it does not remember the conversation at all. Every chat is like a new conversation.
I checked issues and I cant find the same problem I am having.(Or I did not look enough. Forgive me.)
I made this basic prototype with chat stream to test.
Is there a doc somewhere I can use as guide for more use cases like persistent memory/context using the model's context size? Similar to how Ollama run works where the chat is continuous. Thanks.
@ArnoldIOI commented on GitHub (Aug 1, 2024):
You need to keep the conversation in your
messageshereresponse = ollama.chat(model=model, messages=messages, stream=True)Ollama's official doc provides an example on this.
@kikoferrer commented on GitHub (Aug 9, 2024):
Does this mean declaring an empty list
[]asmessagesvariable and inserting each conversation turn to creat a conversation history, then using the while chat history as prompt for the chat?@kikoferrer commented on GitHub (Aug 9, 2024):
Figured it out. For anyone who might encounter the same question, I will leave the bare bone code here. It can certainly remember previous conversation.
Though I am unable to recreate this with streaming=True. Anyone who can figure out to do this in streaming mode please let me know. Thanks
@ArnoldIOI commented on GitHub (Aug 10, 2024):
I wrote this based on the examples you provided, which worked for me.
I think the problem you met (to maintain the history with steaming=True) is to get the complete response properly.
@dyexlzc commented on GitHub (Aug 15, 2024):
hi,i hava same question too.
i found there has a simple parameter in api /generate:
https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-completion
request:
response:
i wonder if i use /api/chat and want to keep memory, means only can store message at client(such as python script) and send all history message like {"role":"user",“content":"xxxx"} in the POST request body?
is there have a same things for /api/chat like parameter
contextin /api/generate? thanks for all!@dyexlzc commented on GitHub (Aug 15, 2024):
or is there are any different between use /api/generate with
contextand use /api/chat with all history message@jwaitzel commented on GitHub (Sep 7, 2024):
Hello, I'm having the same issue, I'm learning to use llms so probably I'm missing something, but with Strem=False, I'm sending all the message history, but the model reply to all my messages together. I attach an example.
@ParthSareen commented on GitHub (Nov 26, 2024):
Closing this out - we have an example under the examples directory :D