Thread memory for AI agents
Project description
threadmem
Chat thread memory for AI agents
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Threadmem is a simple tool that helps manage chat conversations with language models.
Installation
pip install threadmem
Usage
Role Threads
Role based threads are useful for managing openai-style chat schemas.
from threadmem import RoleThread
# Create a thread storing it in a local sqlite db
thread = RoleThread(owner_id="dolores@agentsea.ai")
# Post messages
thread.post("user", "Hello, Thread!")
thread.post("assistant", "How can I help?")
thread.post("user", "Whats this image?", images=["data:image/jpeg;base64,..."])
# Output in openai chat schema format
print(thread.to_oai())
# Find a thread
threads = RoleThread.find(owner_id="dolores@agentsea.ai")
# Delete a thread
threads[0].delete()
Add images of any variety to the thread, we support base64, filepath, PIL Image, and url
from PIL import Image
img1 = Image.open("img1.png")
thread.post(
role="user",
msg="Whats this image?",
images=["data:image/jpeg;base64,...", "./img1.png", img1, "https://shorturl.at/rVyAS"]
)
Backends
Thread and prompt storage can be backed by:
- Sqlite
- Postgresql
Sqlite will be used by default. To use postgres simply configure the env vars:
DB_TYPE=postgres
DB_NAME=threads
DB_HOST=localhost
DB_USER=postgres
DB_PASS=abc123
Image storage by default will utilize the db, to configure bucket storage using GCS.
- Create a bucket with fine grained permissions
- Create a GCP service account JSON with permissions to write to the bucket
export THREAD_STORAGE_SA_JSON='{
"type": "service_account",
...
}'
export THREAD_STORAGE_BUCKET=my-bucket
Develop
To test
make test
To publish
make publish
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file threadmem-0.2.29.tar.gz
.
File metadata
- Download URL: threadmem-0.2.29.tar.gz
- Upload date:
- Size: 23.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.1 Darwin/22.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c6bcd88af8f4da527c1909fd83ab9c16bb7258b83ae59e134437466b020139a |
|
MD5 | 7a5744a0fbb5c39250c66dd11c3732df |
|
BLAKE2b-256 | d6e92187139123a6b605c76b770065907031eee7f96246b7f71b091537b46922 |
File details
Details for the file threadmem-0.2.29-py3-none-any.whl
.
File metadata
- Download URL: threadmem-0.2.29-py3-none-any.whl
- Upload date:
- Size: 27.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.1 Darwin/22.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf0220288245b9058cdfd095b6e323e344285917ec5e538f5d96891ccfa9a14d |
|
MD5 | 23b6e5cc23188b8b72170c98cd433359 |
|
BLAKE2b-256 | 4643fed477c7936db9af412207fe021cd8b985169994354503b5a1984c932b23 |