-
Notifications
You must be signed in to change notification settings - Fork 590
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
Add in simple to use iterative chat (chat with history) #63
Comments
@mxyng tagging you to get some initial thoughts on this issue and PR. |
Thanks for the interest in ollama-python. The current intention for this library is to mirror the Ollama API and is minimal as a result. Implementing memory as part of the library is out of scope. Memory can be implemented easily by manipulating the from ollama import chat
messages = [
{'role': 'user', 'content': 'Tell me a Joke in less than 30 words.'},
]
response = chat('mistral', messages=messages)
message = response['message']
print(message['content'])
messages.append(message)
messages.append({'role': 'user', 'content': 'Another please.'})
response = chat('mistral', messages=messages)
message = response['message']
print(message['content'])
messages.append(message) This example will print two jokes. Here's what
This full example provides a working version of the above with a few extra bells and whistles. It's effectively a trimmed down version of |
I am not sure if you saw the PR submitted to solve this. Its very simple and seems worthwhile to add to scope.#64 |
I did see the PR. The PR changes the synchronous client to subclass a new client with internal state and adds a method iterative_chat which uses the internal state in place of messages. A stateful client is problematic since now there now needs to be functions to manage the internal state such as trimming or resetting state. This adds additional scope and complexity to library for features that are user specific. Additionally, using a single client for two sets of history is impossible since this client maintains a single history list. The optional Overall, it's a lot of effort and code to implement something the user can implement easily and with more precision |
Fair points. I still see a large need for this. I will probably just end up creating an external library that streamlines this process. |
That would be great! This library is intended to be a building block on which others such as yourself can build more featureful projects |
For example a function like:
Should return two jokes.
The text was updated successfully, but these errors were encountered: