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 <hw.chase.17@gmail.com>
pull/22372/head^2
nold 4 months ago committed by GitHub
parent 01783d67fc
commit 226802f0c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,16 +1,22 @@
"""Tool for the SearxNG search API.""" """Tool for the SearxNG search API."""
from typing import Optional from typing import Optional, Type
from langchain_core.callbacks import ( from langchain_core.callbacks import (
AsyncCallbackManagerForToolRun, AsyncCallbackManagerForToolRun,
CallbackManagerForToolRun, 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_core.tools import BaseTool
from langchain_community.utilities.searx_search import SearxSearchWrapper 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): class SearxSearchRun(BaseTool):
"""Tool that queries a Searx instance.""" """Tool that queries a Searx instance."""
@ -22,6 +28,7 @@ class SearxSearchRun(BaseTool):
) )
wrapper: SearxSearchWrapper wrapper: SearxSearchWrapper
kwargs: dict = Field(default_factory=dict) kwargs: dict = Field(default_factory=dict)
args_schema: Type[BaseModel] = SearxSearchQueryInput
def _run( def _run(
self, self,

Loading…
Cancel
Save