-
Notifications
You must be signed in to change notification settings - Fork 52
/
Combination_of_both.py
46 lines (34 loc) · 1.24 KB
/
Combination_of_both.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
37
38
39
40
41
42
43
44
45
46
#https://python.langchain.com/docs/modules/agents/tools/multi_input_tool
from langchain import OpenAI, LLMMathChain, SerpAPIWrapper
from langchain.agents import initialize_agent, Tool, AgentExecutor
from langchain.chat_models import ChatOpenAI
import os
import chainlit as cl
from langchain.chat_models import ChatOpenAI
from langchain.agents import load_tools, initialize_agent, AgentType
import os
from langchain.chat_models import ChatOpenAI
from langchain.agents import initialize_agent
from langchain.agents import AgentType
import os
from langchain.tools import ShellTool
shell_tool = ShellTool()
@cl.on_chat_start
def start():
llm = ChatOpenAI(temperature=0)
shell_tool.description = shell_tool.description + f"args {shell_tool.args}".replace(
"{", "{{"
).replace("}", "}}")
agent = initialize_agent(
[shell_tool],
llm,
agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
verbose=True,
handle_parsing_errors = True
)
cl.user_session.set("agent", agent)
@cl.on_message
async def main(message):
agent = cl.user_session.get("agent") # type: AgentExecutor
cb = cl.LangchainCallbackHandler(stream_final_answer=True)
await cl.make_async(agent.run)(message, callbacks=[cb])