Zack Saadioui
8/25/2024
1
2
3
4
5
python
from langchain.memory import ConversationBufferMemory
memory = ConversationBufferMemory()
memory.chat_memory.add_user_message("Hi there!")
memory.chat_memory.add_ai_message("Hello! How can I assist you today?")
1
2
bash
pip install langchain langchain-openai
1
2
bash
export OPENAI_API_KEY='your-api-key'
1 2
from langchain.llms import OpenAI llm = OpenAI(temperature=0.5, openai_api_key=os.environ['OPENAI_API_KEY'])
1 2
from langchain.memory import ConversationBufferMemory memory = ConversationBufferMemory()
1 2
from langchain.chains import ConversationChain conversation = ConversationChain(llm=llm, memory=memory)
1
2
3
4
python
response1 = conversation.predict(input="Hello, who are you?")
response2 = conversation.predict(input="What can you do?")
response3 = conversation.predict(input="Tell me more about yourself.")
Copyright © Arsturn 2024