Motörhead Memory (Managed)
Motörhead 是一个用 Rust 实现的内存服务器。它在后台自动处理增量摘要,并允许无状态应用程序。
设置
请参阅 Motörhead 上的说明以运行 Motorhead 的托管版本。您可以通过在 Metal 上创建一个帐户来获取您的 api_key
和 client_id
。
from langchain.memory.motorhead_memory import MotorheadMemory
from langchain import OpenAI, LLMChain, PromptTemplate
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(
api_key="YOUR_API_KEY",
client_id="YOUR_CLIENT_ID"
session_id="testing-1",
memory_key="chat_history"
)
await memory.init(); # 从 Motörhead 加载先前的状态 🤘
llm_chain = LLMChain(
llm=OpenAI(),
prompt=prompt,
verbose=True,
memory=memory,
)
llm_chain.run("hi im bob")
> 进入新的 LLMChain 链...
格式化后的提示:
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?'
llm_chain.run("whats my name?")
> 进入新的 LLMChain 链...
格式化后的提示:
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?'
llm_chain.run("whats for dinner?")
> 进入新的 LLMChain 链...
格式化后的提示:
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:
> 完成链。
" I'm sorry, I'm not sure what you're asking. Could you please rephrase your question?"