mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-03 20:16:52 +00:00
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>
This commit is contained in:
@@ -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,
|
||||||
|
Reference in New Issue
Block a user