-
Couldn't load subscription status.
- Fork 2.1k
fix: #2839 argument reference error #2877
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 all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -391,8 +391,8 @@ def _function_declaration_to_tool_param( | |||||
| }, | ||||||
| }, | ||||||
| } | ||||||
|
|
||||||
| if function_declaration.parameters.required: | ||||||
| if function_declaration.parameters and function_declaration.parameters.required: | ||||||
|
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. medium: Consider simplifying this condition by using the walrus operator to reduce redundancy. if params := function_declaration.parameters and params.required:
Suggested change
|
||||||
| tool_params["function"]["parameters"][ | ||||||
| "required" | ||||||
| ] = function_declaration.parameters.required | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -731,6 +731,23 @@ def test_maybe_append_user_content( | |
| }, | ||
| }, | ||
| ), | ||
| ( | ||
| "no_arguments_function", | ||
| types.FunctionDeclaration( | ||
| name="function_no_args" | ||
| ), | ||
| { | ||
| "type": "function", | ||
| "function": { | ||
| "name": "function_no_args", | ||
| "description": "", | ||
| "parameters": { | ||
| "type": "object", | ||
| "properties": {}, | ||
| }, | ||
| }, | ||
| }, | ||
| ) | ||
|
Comment on lines
+734
to
+750
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. high: Adding a test case for a function with no arguments is a good way to ensure that the fix works as expected. This test case covers the scenario where |
||
| ] | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
high: This change adds a check for
function_declaration.parametersbefore accessing therequiredattribute. This prevents an AttributeError whenfunction_declaration.parametersis None. This is good defensive programming, as it prevents the code from crashing when encountering unexpected input. However, it would be better to add a comment explaining why this check is necessary, and what kind of input would causefunction_declaration.parametersto be None.