mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-06 01:45:27 +03:00
This pull request adds an enum class for the various types of agents used in the project, located in the `agent_types.py` file. Currently, the project is using hardcoded strings for the initialization of these agents, which can lead to errors and make the code harder to maintain. With the introduction of the new enums, the code will be more readable and less error-prone. The new enum members include: - ZERO_SHOT_REACT_DESCRIPTION - REACT_DOCSTORE - SELF_ASK_WITH_SEARCH - CONVERSATIONAL_REACT_DESCRIPTION - CHAT_ZERO_SHOT_REACT_DESCRIPTION - CHAT_CONVERSATIONAL_REACT_DESCRIPTION In this PR, I have also replaced the hardcoded strings with the appropriate enum members throughout the codebase, ensuring a smooth transition to the new approach.
5.4 KiB
5.4 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 [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 [ ]: