-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconversation_summary_memory.py
More file actions
38 lines (31 loc) · 1.23 KB
/
conversation_summary_memory.py
File metadata and controls
38 lines (31 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -------------------------------
# | conversation_summary_memory |
# -------------------------------
import os
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from langchain.chains import ConversationChain
from langchain.memory import ConversationSummaryMemory
load_dotenv()
llm = ChatOpenAI(
model="gpt-3.5-turbo",
api_key=os.getenv("OPENAI_API_KEY"),
temperature=0.7
)
messages = [
"I want to visit a place in Brazil known for its cold weather and botanical park. Can you recommend one?",
"What is the best time of year to visit in terms of weather?",
"What kinds of outdoor activities are available?",
"Any eco-friendly accommodation suggestions there?",
"List 20 other cities with similar characteristics to what we've discussed. Rank them by how interesting they are, and include the one you already suggested.",
"For the first city you mentioned earlier, give me 5 restaurants to visit. Respond with only the name of the city and the restaurant names."
]
memory = ConversationSummaryMemory(llm=llm)
conversation = ConversationChain(
llm=llm,
verbose=True,
memory=memory
)
for message in messages:
response = conversation.predict(input=message)
print(response)