mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-05 17:35:28 +03:00
4.1 KiB
4.1 KiB
In [1]:
from langchain.llms import OpenAI
from langchain.agents import initialize_agent, Tool
from langchain.agents import AgentTypeIn [2]:
def multiplier(a, b):
return a * b
def parsing_multiplier(string):
a, b = string.split(",")
return multiplier(int(a), int(b))In [3]:
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=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)In [4]:
mrkl.run("What is 3 times 4")Out [4]:
[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 chain.[0m
'3 times 4 is 12'
In [ ]: