From 226802f0c4d121b4c9243a7b0959c37b62991587 Mon Sep 17 00:00:00 2001 From: nold Date: Tue, 18 Jun 2024 19:27:39 +0200 Subject: [PATCH] community: add args_schema to SearxSearch (#22954) This change adds args_schema (pydantic BaseModel) to SearxSearchRun for correct schema formatting on LLM function calls Issue: currently using SearxSearchRun with OpenAI function calling returns the following error "TypeError: SearxSearchRun._run() got an unexpected keyword argument '__arg1' ". This happens because the schema sent to the LLM is "input: '{"__arg1":"foobar"}'" while the method should be called with the "query" parameter. --------- Co-authored-by: Harrison Chase --- .../langchain_community/tools/searx_search/tool.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/community/langchain_community/tools/searx_search/tool.py b/libs/community/langchain_community/tools/searx_search/tool.py index b9f4e1b25a3..da99a90b8d2 100644 --- a/libs/community/langchain_community/tools/searx_search/tool.py +++ b/libs/community/langchain_community/tools/searx_search/tool.py @@ -1,16 +1,22 @@ """Tool for the SearxNG search API.""" -from typing import Optional +from typing import Optional, Type from langchain_core.callbacks import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) -from langchain_core.pydantic_v1 import Extra, Field +from langchain_core.pydantic_v1 import BaseModel, Extra, Field from langchain_core.tools import BaseTool from langchain_community.utilities.searx_search import SearxSearchWrapper +class SearxSearchQueryInput(BaseModel): + """Input for the SearxSearch tool.""" + + query: str = Field(description="query to look up on searx") + + class SearxSearchRun(BaseTool): """Tool that queries a Searx instance.""" @@ -22,6 +28,7 @@ class SearxSearchRun(BaseTool): ) wrapper: SearxSearchWrapper kwargs: dict = Field(default_factory=dict) + args_schema: Type[BaseModel] = SearxSearchQueryInput def _run( self,