跳到主要內容
Open In ColabOpen on GitHub

Motörhead

Motörhead 是一個以 Rust 實作的記憶體伺服器。它會在背景自動處理增量摘要,並允許無狀態應用程式。

設定

請參閱 Motörhead 上的說明,以了解如何在本地端執行伺服器。

from langchain_community.memory.motorhead_memory import MotorheadMemory
API 參考:MotorheadMemory

範例

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="https://127.0.0.1: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,
)
API 參考:LLMChain | PromptTemplate | OpenAI
llm_chain.run("hi im bob")


> Entering new LLMChain chain...
Prompt after formatting:
You are a chatbot having a conversation with a human.


Human: hi im bob
AI:

> Finished chain.
' Hi Bob, nice to meet you! How are you doing today?'
llm_chain.run("whats my name?")


> 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.
' You said your name is Bob. Is that correct?'
llm_chain.run("whats for dinner?")


> 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.
"  I'm sorry, I'm not sure what you're asking. Could you please rephrase your question?"

此頁面是否有所幫助?