mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-06 01:45:27 +03:00
5.4 KiB
5.4 KiB
In [1]:
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.agents import AgentType
from langchain.llms import OpenAIIn [2]:
llm = OpenAI(temperature=0)In [3]:
tools = load_tools(["serpapi", "llm-math"], llm=llm)In [6]:
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)In [13]:
agent.run("Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?")Out [13]:
[1m> Entering new AgentExecutor chain...[0m [32;1m[1;3m I need to find out who Leo DiCaprio's girlfriend is and then calculate her age raised to the 0.43 power. Action: Search Action Input: "Leo DiCaprio girlfriend"[0m Observation: [36;1m[1;3mCamila Morrone[0m Thought:[32;1m[1;3m I need to find out Camila Morrone's age Action: Search Action Input: "Camila Morrone age"[0m Observation: [36;1m[1;3m25 years[0m Thought:[32;1m[1;3m I need to calculate 25 raised to the 0.43 power Action: Calculator Action Input: 25^0.43[0m Observation: [33;1m[1;3mAnswer: 3.991298452658078 [0m Thought:[32;1m[1;3m I now know the final answer Final Answer: Camila Morrone is Leo DiCaprio's girlfriend and her current age raised to the 0.43 power is 3.991298452658078.[0m [1m> Finished chain.[0m
"Camila Morrone is Leo DiCaprio's girlfriend and her current age raised to the 0.43 power is 3.991298452658078."
In [ ]: