mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-13 21:47:12 +00:00
fix(core): fix support of Pydantic v1 models in BaseTool.args (#32487)
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
This commit is contained in:
committed by
GitHub
parent
c68796579e
commit
5fd7962a78
@@ -546,6 +546,8 @@ class ChildTool(BaseTool):
|
||||
"""
|
||||
if isinstance(self.args_schema, dict):
|
||||
json_schema = self.args_schema
|
||||
elif self.args_schema and issubclass(self.args_schema, BaseModelV1):
|
||||
json_schema = self.args_schema.schema()
|
||||
else:
|
||||
input_schema = self.get_input_schema()
|
||||
json_schema = input_schema.model_json_schema()
|
||||
|
@@ -64,11 +64,7 @@ class Tool(BaseTool):
|
||||
The input arguments for the tool.
|
||||
"""
|
||||
if self.args_schema is not None:
|
||||
if isinstance(self.args_schema, dict):
|
||||
json_schema = self.args_schema
|
||||
else:
|
||||
json_schema = self.args_schema.model_json_schema()
|
||||
return json_schema["properties"]
|
||||
return super().args
|
||||
# For backwards compatibility, if the function signature is ambiguous,
|
||||
# assume it takes a single string input.
|
||||
return {"tool_input": {"type": "string"}}
|
||||
|
@@ -67,16 +67,6 @@ class StructuredTool(BaseTool):
|
||||
|
||||
# --- Tool ---
|
||||
|
||||
@property
|
||||
def args(self) -> dict:
|
||||
"""The tool's input arguments."""
|
||||
if isinstance(self.args_schema, dict):
|
||||
json_schema = self.args_schema
|
||||
else:
|
||||
input_schema = self.get_input_schema()
|
||||
json_schema = input_schema.model_json_schema()
|
||||
return json_schema["properties"]
|
||||
|
||||
def _run(
|
||||
self,
|
||||
*args: Any,
|
||||
|
@@ -1904,6 +1904,11 @@ def test_args_schema_as_pydantic(pydantic_model: Any) -> None:
|
||||
name="some_tool", description="some description", args_schema=pydantic_model
|
||||
)
|
||||
|
||||
assert tool.args == {
|
||||
"a": {"title": "A", "type": "integer"},
|
||||
"b": {"title": "B", "type": "string"},
|
||||
}
|
||||
|
||||
input_schema = tool.get_input_schema()
|
||||
if issubclass(input_schema, BaseModel):
|
||||
input_json_schema = input_schema.model_json_schema()
|
||||
|
Reference in New Issue
Block a user