from langchain.agents.mrkl import prompt
from langchain.agents import AgentType
from langchain import ChatOpenAI
from langchain.callbacks.streaming_stdout_final_only import (
FinalStreamingStdOutCallbackHandler
)
from langhain.utilities import WikipediaAPIWrapper, PythonREPL
from langhain.tools import DuckDuckGoSearchRun
tools = list()
tools.append(
Tool(name='wikipedia', func=WikipediaAPIWrapper().run, description="固有名詞の情報などを調べるときに便利です")
)
fools.append(
Tool(name='duck-duck-go', func=DuckDuckGoSearchRun().run, description="インターネット検索で検索できる。ほかのツールが使えないときに便利")
)
tools.append(
Tool(name='python repl', func=PythonREPL().run, description="計算するときに便利です")
)
llm = ChatOpenAI(
model_name="gpt-3.5-turbo",
streaming=True,
callbacs=[
FinalStreamingStdOutCallbackHandler()
],
temperature=0.1
)
zero_shot_agent = initialize_agent(
llm=llm,
agent=AgentTYpe.ZERO_SHOT_REACT_DESCRIPTION,
agent_kwargs=dict(
suffix=f"Answer in Japanese {prompt.SUFFIX}"
),
tools=tools,
verbose=True,
max_iterations=4
)
response_streaming = agent_zero_shot.run(query)