mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
Add in simple to use iterative chat (chat with history) #30
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 @connor-makowski on GitHub (Feb 13, 2024).
For example a function like:
Should return two jokes.
@connor-makowski commented on GitHub (Feb 15, 2024):
@mxyng tagging you to get some initial thoughts on this issue and PR.
@mxyng commented on GitHub (Feb 21, 2024):
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
messageskeyword argument. Here's a quick example:This example will print two jokes. Here's what
mistralgave meThis full example provides a working version of the above with a few extra bells and whistles. It's effectively a trimmed down version of
ollama run(with--speakfor fun).@connor-makowski commented on GitHub (Feb 21, 2024):
I am not sure if you saw the PR submitted to solve this. Its very simple and seems worthwhile to add to scope.https://github.com/ollama/ollama-python/pull/64
@mxyng commented on GitHub (Feb 21, 2024):
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
historykeyword argument functions roughly the same as the currentmessageskeyword argument by manipulating the internal state. However it's error prone since sending the same history twice will add duplicate entries.Overall, it's a lot of effort and code to implement something the user can implement easily and with more precision
@connor-makowski commented on GitHub (Feb 21, 2024):
Fair points. I still see a large need for this. I will probably just end up creating an external library that streamlines this process.
@mxyng commented on GitHub (Feb 21, 2024):
That would be great! This library is intended to be a building block on which others such as yourself can build more featureful projects