Simple LLM Memory
Project description
Memento: Simple LLM Memory
Memento is a conversation management API for llm applications. It interfaces with your SQL database of choice to handle conversational histories.
Memento uses SQLAlchemy and Alembic under the hood to interact with SQL databases, so any database that is supported by these libraries (PostgreSQL, MySQL, SQLite, CosmoDB, etc.) is also supported by Memento.
Installation
$ pip install memento-llm
Getting Started
With Memento, you no longer have to worry about setting up message storage logic in your application, allowing for a seamlessly stateless flow, here is how it can be integrated into your code:
Recorder API
Currently Memento only has the Recorder
API, which serves as a simple way to use Memento in applications dependent on SQLAlchemy sessions. Because of this fact, it is a natural fit for FastAPI applications (which is my main use for Memento, personally).
The main differentiator of the Recorder API is that it requires that a SQLAlchemy Session
or AsyncSession
be provided. The same base Recorder class has methods to use both types of sessions.
from openai import OpenAI
from memento import Recorder, crud, models
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
# Setup
client = OpenAI()
engine = create_engine("sqlite://") # In-memory sqlite database
models.Base.metadata.create_all(engine) # For demo purposes, create tables with the metadata API
with Session(engine) as session:
conversation_id = crud.create_conversation(session, "Testbot") # Name of the assistant/agent/app
# Usage
def generate():
# Start the recorder with previous conversation data (Empty the during the first call, one message during the second)
recorder = Recorder.from_conversation(session, conversation_id)
# Call the LLM API with data retrieved from the recorder
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=recorder.to_openai_format()
)
# Add the response to the recorder
recorder.add_openai_response(response)
# Commit new messages to your database
recorder.commit_new_messages(session)
response_1 = generate("My name is Anibal")
print(response_1) # Output: Hello Anibal!
response_2 = generate("What´s my name?")
print(response_2) # Output: Your name is Anibal.
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 memento_llm-0.2.7.tar.gz
.
File metadata
- Download URL: memento_llm-0.2.7.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-47-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d746479aa962f30790f92669b8ced36ce9d8001df152366a9673a3e6bf34cbcb |
|
MD5 | 76e7ac84249544fe115b646743e78266 |
|
BLAKE2b-256 | 895b0ac8315816e813eacf9e6e7fbaf5b373c66139bcbdb6e44bc7475a4e1dd9 |
File details
Details for the file memento_llm-0.2.7-py3-none-any.whl
.
File metadata
- Download URL: memento_llm-0.2.7-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-47-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1bd6725a6a7c06d6c3bc2eee9509b970821815b6c1d29208df843f0989287bd |
|
MD5 | 70437e80fdbb9a7e756208192ef3f84f |
|
BLAKE2b-256 | 8c89e78565f5c02066953c577e62b286626fa870b1e2a4459da51c265746d830 |