Motörhead is a memory server implemented in Rust. It automatically handles incremental summarization in the background and allows for stateless applications.
Setup
See instructions at Motörhead for running the server locally.Copy
Ask AI
from langchain_community.memory.motorhead_memory import MotorheadMemory
Example
Copy
Ask AI
from langchain.chains import LLMChain
from langchain_core.prompts import PromptTemplate
from langchain_openai import OpenAI
template = """You are a chatbot having a conversation with a human.
{chat_history}
Human: {human_input}
AI:"""
prompt = PromptTemplate(
input_variables=["chat_history", "human_input"], template=template
)
memory = MotorheadMemory(
session_id="testing-1", url="http://localhost:8080", memory_key="chat_history"
)
await memory.init()
# loads previous state from Motörhead 🤘
llm_chain = LLMChain(
llm=OpenAI(),
prompt=prompt,
verbose=True,
memory=memory,
)
Copy
Ask AI
llm_chain.run("hi im bob")
Copy
Ask AI
> Entering new LLMChain chain...
Prompt after formatting:
You are a chatbot having a conversation with a human.
Human: hi im bob
AI:
> Finished chain.
Copy
Ask AI
' Hi Bob, nice to meet you! How are you doing today?'
Copy
Ask AI
llm_chain.run("whats my name?")
Copy
Ask AI
> Entering new LLMChain chain...
Prompt after formatting:
You are a chatbot having a conversation with a human.
Human: hi im bob
AI: Hi Bob, nice to meet you! How are you doing today?
Human: whats my name?
AI:
> Finished chain.
Copy
Ask AI
' You said your name is Bob. Is that correct?'
Copy
Ask AI
llm_chain.run("whats for dinner?")
Copy
Ask AI
> Entering new LLMChain chain...
Prompt after formatting:
You are a chatbot having a conversation with a human.
Human: hi im bob
AI: Hi Bob, nice to meet you! How are you doing today?
Human: whats my name?
AI: You said your name is Bob. Is that correct?
Human: whats for dinner?
AI:
> Finished chain.
Copy
Ask AI
" I'm sorry, I'm not sure what you're asking. Could you please rephrase your question?"