mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-07 18:35:22 +03:00
Co-authored-by: James O'Dwyer <100361543+softboyjimbo@users.noreply.github.com>
4.6 KiB
4.6 KiB
In [1]:
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(
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,
)
In [2]:
llm_chain.run("hi im bob")Out [2]:
[1m> Entering new LLMChain chain...[0m Prompt after formatting: [32;1m[1;3mYou are a chatbot having a conversation with a human. Human: hi im bob AI:[0m [1m> Finished chain.[0m
' Hi Bob, nice to meet you! How are you doing today?'
In [3]:
llm_chain.run("whats my name?")Out [3]:
[1m> Entering new LLMChain chain...[0m Prompt after formatting: [32;1m[1;3mYou 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:[0m [1m> Finished chain.[0m
' You said your name is Bob. Is that correct?'
In [4]:
llm_chain.run("whats for dinner?")Out [4]:
[1m> Entering new LLMChain chain...[0m Prompt after formatting: [32;1m[1;3mYou 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:[0m [1m> Finished chain.[0m
" I'm sorry, I'm not sure what you're asking. Could you please rephrase your question?"
In [ ]: