-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatAgent.py
36 lines (27 loc) · 905 Bytes
/
ChatAgent.py
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
from langchain.agents import Tool, initialize_agent
from langchain.chains.conversation.memory import ConversationBufferWindowMemory
from langchain.chat_models import ChatOpenAI
# Set up the turbo LLM
turbo_llm = ChatOpenAI(
temperature=0,
model_name='gpt-3.5-turbo'
)
class ChatAgent:
def __init__(self, tools):
self.tools = tools
self.memory = ConversationBufferWindowMemory(
memory_key='chat_history',
k=3,
return_messages=True
)
self.conversational_agent = initialize_agent(
agent='chat-conversational-react-description',
tools=tools,
llm=turbo_llm,
verbose=True,
max_iterations=3,
early_stopping_method='generate',
memory=self.memory
)
def chat(self, message):
return self.conversational_agent(message)