mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-06 18:05:25 +03:00
Big docs refactor! Motivation is to make it easier for people to find resources they are looking for. To accomplish this, there are now three main sections: - Getting Started: steps for getting started, walking through most core functionality - Modules: these are different modules of functionality that langchain provides. Each part here has a "getting started", "how to", "key concepts" and "reference" section (except in a few select cases where it didnt easily fit). - Use Cases: this is to separate use cases (like summarization, question answering, evaluation, etc) from the modules, and provide a different entry point to the code base. There is also a full reference section, as well as extra resources (glossary, gallery, etc) Co-authored-by: Shreya Rajpal <ShreyaR@users.noreply.github.com>
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 [3]:
llm = OpenAI(temperature=0)In [4]:
tools = load_tools(["serpapi", "llm-math"], llm=llm)In [5]:
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)In [6]:
agent.run("Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?")Out [6]:
[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 AgentExecutor chain.[0m
"Harry Styles is Olivia Wilde's boyfriend and his current age raised to the 0.23 power is 2.1520202182226886."