-
Notifications
You must be signed in to change notification settings - Fork 19k
fix(core): fix support of Pydantic v1 models in BaseTool.args #32487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -543,6 +543,8 @@ def args(self) -> dict: | |
""" | ||
if isinstance(self.args_schema, dict): | ||
json_schema = self.args_schema | ||
elif self.args_schema and issubclass(self.args_schema, BaseModelV1): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BaseModelV1 is imported. |
||
json_schema = self.args_schema.schema() | ||
else: | ||
input_schema = self.get_input_schema() | ||
json_schema = input_schema.model_json_schema() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,16 +67,6 @@ async def ainvoke( | |
|
||
# --- Tool --- | ||
|
||
@property | ||
def args(self) -> dict: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as parent class. |
||
"""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, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1861,6 +1861,11 @@ def _run(self, *args: Any, **kwargs: Any) -> str: | |
name="some_tool", description="some description", args_schema=pydantic_model | ||
) | ||
|
||
assert tool.args == { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without the fix in |
||
"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() | ||
|
Uh oh!
There was an error while loading. Please reload this page.