-
Notifications
You must be signed in to change notification settings - Fork 59
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
handle empty tool call function arguments #717
Conversation
LLMs can return an empty string for no args, so need to handle that case to prevent an error trying to convert to dict from json with jiter.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #717 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 398 398
Lines 13298 13292 -6
=========================================
- Hits 13298 13292 -6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@jimkring good catch! could you also update the remaining 7 providers? |
@willbakst I'll take a look. I did a search and only found those three identical bits of code. Maybe the other providers are subtly different. |
oh you're right because of the issue being with can you update also, i just noticed that |
@willbakst I've updated several other files/providers. Please take a look at how the differ in subtle ways. In some cases the |
happy to provide comments, also happy to take this over the finish line, just let me know :) |
@willbakst it's all yours to finish up, now. Thanks for the style suggestions and fixes -- I learned a couple things 👍 |
…allowing empty function args
this is now released in thank you for the contribution!! |
This pull request includes changes to improve the handling of tool calls in the
mirascope/core
package. The updates ensure that themodel_json
is properly initialized even whentool_call.function.arguments
is empty.Background:
LLMs sometimes use pass an empty string for tool call function args, which was causing an unhandled exception when deserializing the function arguments string to json with jiter.
Solution:
Now, we detect that
tool_call.function.arguments
is empty and simply initialize an empty dictionary (instead of trying to deserialize an empty string).Changes to tool call handling:
mirascope/core/azure/tool.py
: Added a check to initializemodel_json
to an empty dictionary iftool_call.function.arguments
is empty in thefrom_tool_call
method.mirascope/core/groq/tool.py
: Added a check to initializemodel_json
to an empty dictionary iftool_call.function.arguments
is empty in thefrom_tool_call
method.mirascope/core/openai/tool.py
: Added a check to initializemodel_json
to an empty dictionary iftool_call.function.arguments
is empty in thefrom_tool_call
method.