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
.
to_oai
method for exporting the thread to OpenAI format.
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 withThreadMem
. To do that, you pass the remote server URL to the thread constructor: