langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Custom Model with args_schema not working

Open digitaldesaster opened this issue 1 year ago • 3 comments

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]") `

digitaldesaster avatar Apr 23 '23 20:04 digitaldesaster

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

vowelparrot avatar Apr 24 '23 00:04 vowelparrot

many thanks for the quick reply. cheers

digitaldesaster avatar Apr 24 '23 05:04 digitaldesaster

Thanks for your hard work on this guys. Is there any progress on the issue? Cheers!

Sh1d0w avatar May 14 '23 07:05 Sh1d0w

Yeah you can check out https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html?highlight=structured%20chat

vowelparrot avatar May 14 '23 19:05 vowelparrot

@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.

sweetlilmre avatar May 29 '23 07:05 sweetlilmre

link not found. https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html?highlight=structured%20chat @vowelparrot .

yajunDai avatar Jun 28 '23 03:06 yajunDai

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!

dosubot[bot] avatar Sep 27 '23 16:09 dosubot[bot]