Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memento_llm-0.1.9.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

memento_llm-0.1.9-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file memento_llm-0.1.9.tar.gz.

File metadata

  • Download URL: memento_llm-0.1.9.tar.gz
  • Upload date:
  • Size: 4.3 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

Hashes for memento_llm-0.1.9.tar.gz
Algorithm Hash digest
SHA256 b15f7a791da10c517e8fd680e302164340a7f82b322adcfe3cc7e3ed69d1e242
MD5 b191642dbcc71a03aa1fcfd2ee451185
BLAKE2b-256 fea47070264e047290e2d82f5088e8b1119ca8c06b817c1ce468f4c923ad3feb

See more details on using hashes here.

File details

Details for the file memento_llm-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: memento_llm-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 5.3 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

Hashes for memento_llm-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 36c44dbd279bcaaeb32d05d4bae1d9d814a6c89c31cb9cc379d712493b5eec61
MD5 84d4a647cdb99010b38a9bf1501299c8
BLAKE2b-256 2844e185bd992e9ff861d1c2654a99d19115e7fdd2b7eb5a00f618906b3d8a0e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page