mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-06 01:45:27 +03:00
3.6 KiB
3.6 KiB
In [1]:
import sys
from langchain.chat_models import ChatOpenAI
from langchain.llms import OpenAI
from langchain.agents import load_tools, initialize_agent
from langchain.agents import AgentType
llm = ChatOpenAI(temperature=0.0)
math_llm = OpenAI(temperature=0.0)
tools = load_tools(
["human", "llm-math"],
llm=math_llm,
)
agent_chain = initialize_agent(
tools,
llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True,
)In [3]:
agent_chain.run("What is Eric Zhu's birthday?")
# Answer with "last week"Out [3]:
[1m> Entering new AgentExecutor chain...[0m [32;1m[1;3mI don't know Eric Zhu, so I should ask a human for guidance. Action: Human Action Input: "Do you know when Eric Zhu's birthday is?"[0m Do you know when Eric Zhu's birthday is? last week Observation: [36;1m[1;3mlast week[0m Thought:[32;1m[1;3mThat's not very helpful. I should ask for more information. Action: Human Action Input: "Do you know the specific date of Eric Zhu's birthday?"[0m Do you know the specific date of Eric Zhu's birthday? august 1st Observation: [36;1m[1;3maugust 1st[0m Thought:[32;1m[1;3mNow that I have the date, I can check if it's a leap year or not. Action: Calculator Action Input: "Is 2021 a leap year?"[0m Observation: [33;1m[1;3mAnswer: False [0m Thought:[32;1m[1;3mI have all the information I need to answer the original question. Final Answer: Eric Zhu's birthday is on August 1st and it is not a leap year in 2021.[0m [1m> Finished chain.[0m
"Eric Zhu's birthday is on August 1st and it is not a leap year in 2021."
In [ ]: