mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-07 18:35:22 +03:00
Co-authored-by: Stefan Keselj <skeselj@princeton.edu> Co-authored-by: Harrison Chase <harrisonchase@Harrisons-MBP.attlocal.net>
5.2 KiB
5.2 KiB
In [1]:
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.llms import OpenAIIn [2]:
llm = OpenAI(temperature=0)In [3]:
tools = load_tools(["serpapi", "llm-math"], llm=llm)In [4]:
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)In [5]:
agent.run("Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?")Out [5]:
[1m> Entering new AgentExecutor chain...[0m [32;1m[1;3m I need to find out who Olivia Wilde's boyfriend is and then calculate his age raised to the 0.23 power. Action: Search Action Input: "Olivia Wilde boyfriend"[0m Observation: [36;1m[1;3mHarry Styles[0m Thought:[32;1m[1;3m I need to find out Harry Styles' age Action: Search Action Input: "Harry Styles age"[0m Observation: [36;1m[1;3m28 years[0m Thought:[32;1m[1;3m I need to calculate 28 raised to the 0.23 power Action: Calculator Action Input: 28^0.23[0m Observation: [33;1m[1;3mAnswer: 2.1520202182226886 [0m Thought:[32;1m[1;3m I now know the final answer Final Answer: Harry Styles is Olivia Wilde's boyfriend and his current age raised to the 0.23 power is 2.1520202182226886.[0m [1m> Finished chain.[0m
"Harry Styles is Olivia Wilde's boyfriend and his current age raised to the 0.23 power is 2.1520202182226886."