10000 Fix Tool.to_dict for nullable input parameter by albertvillanova · Pull Request #1038 · huggingface/smolagents · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix Tool.to_dict for nullable input parameter #1038

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 25, 2025

Conversation

albertvillanova
Copy link
Member

Fix Tool.to_dict for nullable input parameter.

Currently, nullable parameters are exported to dict with nullable value as true, which is not valid Python syntax.

"nullable":true

@albertvillanova
Copy link
Member Author

@@ -222,7 +222,7 @@ def to_dict(self) -> dict:
class {class_name}(Tool):
name = "{self.name}"
description = {json.dumps(textwrap.dedent(self.description).strip())}
inputs = {json.dumps(self.inputs, separators=(",", ":"))}
inputs = {self.inputs}
Copy link
Collaborator
@aymeric-roucher aymeric-roucher Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What prompted me to use this json.dumps was that only using fstring here meant that some dicts would be converted to strings poorly, this fixed it. Also this new version may show dict keys with simple quotes, is this intended?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Python, there is no difference between using single (') or double (") quotes for strings: they are interchangeable.

Regarding the formatting, instead of using an f-string, I could use the repr function. This ensures that the dictionary representation remains evaluable/executable while preserving its structure more reliably.

@albertvillanova albertvillanova merged commit ee07d40 into huggingface:main Mar 25, 2025
3 checks passed
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.

2 participants
0