I am trying to make an agent using the Langchain framework. My goal is to create an agent that places orders to a store for me. The function/Tool I am using to place the order needs multiple inputs to run. I keep getting this error TypeError: __init__() takes 1 positional argument but 7 were given
我正在尝试使用LangChain框架来制作一个代理。我的目标是创建一个为我向商店下单的代理。我用来下单的功能/工具需要多个输入才能运行。我一直收到此错误类型错误:__init__()接受1个位置参数,但给出了7个
from placeorder import order_three
from langchain.chat_models import ChatOpenAI
from pydantic import BaseModel, Field
from typing import Optional, Type
from langchain.agents import AgentType
from langchain.tools import BaseTool
from langchain.agents import initialize_agent, Tool
class order_three(BaseModel):
"""Place an order"""
first_name: str =Field(...,description= "The first name of person placing the order")
last_name: str =Field(...,description= "The last name of person placing the order")
phone_number: str =Field(...,description= "The phone number of person placing the order")
product: str =Field(...,description= "The product they want to buy")
date_of_birth: str =Field(...,description= "The date of birth of person placing the order")
quantity: str =Field(...,description= "The amount of the product they want to buy")
class order_three(BaseTool):
name = "place_order"
description = "Useful when the user wants to place an order. You should input the firstname, lastname, quantity, product, date of birth, and phone number"
def _run(self, first_name: str, last_name: str, quantity: str, date_of_birth: str, product: str, phone_number: str):
place_order_response = order_three(first_name, last_name, phone_number, date_of_birth, product, quantity)
return place_order_response
def _arun(self, first_name: str, last_name: str, quantity: str, date_of_birth: str, product: str, phone_number: str):
raise NotImplementedError("This tool does not support async")
args_schema: Optional[Type[BaseModel]] = order_three
tools = [order_three()]
llm = ChatOpenAI(temperature=0, model="gpt-3.5-turbo-0613")
open_ai_agent = initialize_agent(tools,
llm,
agent=AgentType.OPENAI_FUNCTIONS,
verbose=True)
print(open_ai_agent.run("I want to place an order. My name is John smith my phone number is 5555555555. my date of birth is 030419999 I want to order 8 large Pizzas"))
Here's what I am getting back
这是我得到的
Entering new AgentExecutor chain...
Invoking: place_order
with {'first_name': 'John', 'last_name': 'Smith', 'phone_number': '5555555555', 'product': 'large Pizzas', 'date_of_birth': '03041999', 'quantity': '8'}
调用:Place_Order With{‘First_Name’:‘John’,‘Last_Name’:‘Smith’,‘Phone_Number’:‘5555555555’,‘Product’:‘大型披萨’,‘Date_of_Birth’:‘03041999’,‘Quantity’:‘8’}
Traceback (most recent call last):
File "/Users/izayahhudnut/Documents/Code/BudtenderAI/vite-project/testagent.py", line 45, in <module>
print(open_ai_agent.run("I want to place an order. My name is John smith my phone number is 5555555555. my date of birth is 030419999 I want to order 8 large Pizzas"))
File "/Users/izayahhudnut/Library/Python/3.9/lib/python/site-packages/langchain/chains/base.py", line 487, in run
return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
File "/Users/izayahhudnut/Library/Python/3.9/lib/python/site-packages/langchain/chains/base.py", line 292, in __call__
raise e
File "/Users/izayahhudnut/Library/Python/3.9/lib/python/site-packages/langchain/chains/base.py", line 286, in __call__
self._call(inputs, run_manager=run_manager)
File "/Users/izayahhudnut/Library/Python/3.9/lib/python/site-packages/langchain/agents/agent.py", line 1039, in _call
next_step_output = self._take_next_step(
File "/Users/izayahhudnut/Library/Python/3.9/lib/python/site-packages/langchain/agents/agent.py", line 894, in _take_next_step
observation = tool.run(
File "/Users/izayahhudnut/Library/Python/3.9/lib/python/site-packages/langchain/tools/base.py", line 356, in run
raise e
File "/Users/izayahhudnut/Library/Python/3.9/lib/python/site-packages/langchain/tools/base.py", line 330, in run
else self._run(*tool_args, **tool_kwargs)
File "/Users/izayahhudnut/Documents/Code/BudtenderAI/vite-project/testagent.py", line 25, in _run
place_order_response = order_three(first_name, last_name, phone_number, date_of_birth, product, quantity)
TypeError: __init__() takes 1 positional argument but 7 were given
更多回答
please format your question prperly, not able to understand anything.
请用正确的格式提问,什么都听不懂。
Your order_three is a class you have defined. It does not define a constructor (__init__
). Therefore it has an empty default-constructor, which takes 1 argument (self
). You are passing 7.
您的Order_Three是您定义的类。它没有定义构造函数(__Init__)。因此,它有一个空的默认构造函数,该函数接受1个参数(Self)。你快过7岁了。
You might think that order_three should inherit a constructor from the pydantic-BaseModel. However, you redefine order_three as another class later in the code. That other class has nothing to do with phone_number
and the other fields.
您可能认为Order_Three应该继承来自PYDANIC-BaseModel的构造函数。但是,稍后在代码中将Order_Three重新定义为另一个类。另一个类与phone_number和其他字段无关。
更多回答
我是一名优秀的程序员,十分优秀!