Introduction
ThreadMem
is a library for building and manipulating persistent chat threads. It makes it easier to communicate with LLMs, but it’s not limited to that alone.
For example, you can create a Thread in the code and add messages to it (like, a message from “system”, a message from “user”, a message from “assistant”, from “user” again, etc). The threads get written to a DB (SQLite/Postgres), so you can return to the chat at any time and pick up where you left off.
Installation
Basic Example
By default, the threads you create are stored in a local SQLite database, located at ./data/threads.db
.
As mentioned above, the library is designed for making it easier to communicate with LLMs, so we support a to_oai
method for exporting the thread to OpenAI format.
Add images of any variety to the thread. We support base64, filepath, PIL, and URL:
Using PostgreSQL
To use PostgreSQL as a database backend, you should set up a few environment variables.
Remote Connection
It’s possible to connect to a remote server with ThreadMem
. To do that, you pass the remote server URL to the thread constructor: