langchain
langchain copied to clipboard
Custom Model with args_schema not working
i tried out a simple custom model. as long as i am using only one "query" parameter everything is working fine. in this example i like to use two parameters (i searched the problem and i found this SendMessage usecase...)
unfortunately it does not work.. and throws this error.
input_args.validate({key_: tool_input}) File "pydantic/main.py", line 711, in pydantic.main.BaseModel.validate File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__ pydantic.error_wrappers.ValidationError: 1 validation error for SendMessageInput message field required (type=value_error.missing)
the code :
`from langchain.agents import initialize_agent from langchain.agents import AgentType from langchain.llms import OpenAI
from langchain.tools import BaseTool from typing import Type
from pydantic import BaseModel, Field
class SendMessageInput(BaseModel): email: str = Field(description="email") message: str = Field(description="the message to send")
class SendMessageTool(BaseTool): name = "send_message_tool" description = "useful for when you need to send a message to a human" args_schema: Type[BaseModel] = SendMessageInput
def _run(self, email:str,message:str) -> str:
print(message,email)
"""Use the tool."""
return f"message send"
async def _arun(self, email: str, message: str) -> str:
"""Use the tool asynchronously."""
return f"Sent message '{message}' to {email}"
llm = OpenAI(temperature=0)
tools=[SendMessageTool()]
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
agent.run("send message hello to [email protected]") `
The ZERO_SHOT_REACT_DESCRIPTION
agents don't yet work with multi-argument messages.
The CHAT_ZERO_SHOT_REACT_DESCRIPTION
work better, though the updates to tool descriptoin are still not landed.
We are looking to land fixes in the. next couple of days
many thanks for the quick reply. cheers
Thanks for your hard work on this guys. Is there any progress on the issue? Cheers!
Yeah you can check out https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html?highlight=structured%20chat
@vowelparrot Thank you for this, this solved several days of extreme frustration.
I don't have the OPs use case, just a simple agent with a web search tool, however the difference in result consistency with CHAT_ZERO_SHOT_REACT_DESCRIPTION
vs ZERO_SHOT_REACT_DESCRIPTION
is startling. I'm using GPT4 on a private Azure instance.
link not found. https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html?highlight=structured%20chat @vowelparrot .
Hi, @digitaldesaster! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
From what I understand, you reported an issue regarding a validation error when using a custom model with two parameters. vowelparrot responded and mentioned that the ZERO_SHOT_REACT_DESCRIPTION
agents don't yet work with multi-argument messages, but the CHAT_ZERO_SHOT_REACT_DESCRIPTION
agents work better. They also mentioned that fixes will be landed in the next couple of days. Sh1d0w asked for progress on the issue, and vowelparrot provided a link to an example that might be helpful. sweetlilmre thanked vowelparrot for the link and mentioned that it solved their frustration. However, yajunDai reported that the link provided by vowelparrot is not found.
Before we close this issue, we wanted to check if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.
Thank you for your understanding and contribution to the LangChain project!