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.
Metadata
Release files for memento-llm 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| memento_llm-0.3.3.tar.gz | 5.3 kB | Without provenance | Details for memento_llm-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| memento_llm-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for memento_llm-0.3.3-py3-none-any.whl |
Total release size: 11.9 kB
Release files / memento_llm-0.3.3.tar.gz
| Download URL | memento_llm-0.3.3.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95946962c7acc8c762b52a66c101710d37cf5f7e2e593442b6e8eb890bb200e0
|
|
BLAKE2b-256 checksum How to use checksums |
1c5d22892c6047573cebfcf7dd2a48cfa52f57d943571e895364a4830dab5c0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-48-generic
|
Release files / memento_llm-0.3.3-py3-none-any.whl
| Download URL | memento_llm-0.3.3-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
86d5ac90e94dc827faf3d788832b74ccb31c56135ba1b29c4bfb27524784decb
|
|
BLAKE2b-256 checksum How to use checksums |
f59c98cacc5ef93168846f6704749a955b094803f048ba2c24a59945768f3225
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-48-generic
|
Security for memento-llm 0.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.