mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-07 18:35:22 +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>
4.0 KiB
4.0 KiB
In [1]:
from langchain.llms import OpenAI
from langchain.agents import initialize_agent, ToolIn [2]:
def multiplier(a, b):
return a * b
def parsing_multiplier(string):
a, b = string.split(",")
return multiplier(int(a), int(b))In [6]:
llm = OpenAI(temperature=0)
tools = [
Tool(
name = "Multiplier",
func=parsing_multiplier,
description="useful for when you need to multiply two numbers together. The input to this tool should be a comma separated list of numbers of length two, representing the two numbers you want to multiply together. For example, `1,2` would be the input if you wanted to multiply 1 by 2."
)
]
mrkl = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)In [7]:
mrkl.run("What is 3 times 4")Out [7]:
[1m> Entering new AgentExecutor chain...[0m [32;1m[1;3m I need to multiply two numbers Action: Multiplier Action Input: 3,4[0m Observation: [36;1m[1;3m12[0m Thought:[32;1m[1;3m I now know the final answer Final Answer: 3 times 4 is 12[0m [1m> Finished AgentExecutor chain.[0m
'3 times 4 is 12'
In [ ]: