8000 Fix get_json_schema for docstrings with type annotations by albertvillanova · Pull Request #1088 · huggingface/smolagents · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix get_json_schema for docstrings with type annotations #1088

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

Merged
merged 6 commits into from
Mar 28, 2025

Conversation

albertvillanova
Copy link
Member

Fix get_json_schema for docstrings with type annotations.

Note that this was already addressed by:

However, that PR introduced a bug when parsing multiple arguments: the docstring with

Args:
    x (int): An integer parameter with type in docstring.
    y (float): A float parameter with type in docstring.

was wrongly parsed into (y parameter was included in x description):

{'x': 'An integer parameter with type in docstring. y (float): A float parameter with type in docstring.'}

This PR fixes that issue.

Additionally, this PR fixes the return description when the docstring contains the return type. Before, the docstring

Returns:
    float: The calculated result.

was wrongly parsed (including the return type into the return description):

return_dict["description"] = "float: The calculated result."

Fix #1073.

@sysradium
Copy link
Contributor
sysradium commented Mar 27, 2025

@albertvillanova I found a few edge-cases that aren't covered by your PR and created one on top of it: #1094

It has to be processed line by line to be more stable. That increases complexity a bit : /

@albertvillanova albertvillanova merged commit 337288e into huggingface:main Mar 28, 2025
3 checks passed
@albertvillanova albertvillanova deleted the fix-1073 branch April 8, 2025 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] DocstringParsingException when creating a tool with types in docstring
3 participants
0