-
Notifications
You must be signed in to change notification settings - Fork 18
Empty argument gets encoded as [] instead of {} #243
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
Conversation
lib/Service/OpenAiAPIService.php
Outdated
| 'function' => $toolCall, | ||
| ]; | ||
| $formattedToolCall['function']['arguments'] = json_encode($toolCall['args']); | ||
| $formattedToolCall['function']['arguments'] = json_encode($toolCall['args'], JSON_FORCE_OBJECT); |
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.
how about inspecting the output of json_encode and then converting it to an object?
It's only an issue when it's empty, right?
$out = json_encode($toolCall['args']) ?: '[]';
if ($out === '[]') {
$out = '{}';
}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.
That's a much better and simple idea. Technically it might still be an issue if one of the parameters in an argument needs to be an empty object, but I don't think that is common and might not even be possible.
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.
A full blown inspection can be done as well looping over all the properties and converting every empty key-val array [] to an empty object (object) [] but if that case is not possible, this is good enough.
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.
That also isn't always wanted because I think it is possible to pass an empty array as an argument like below.
{"features":[]}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.
ah right
0324fc6 to
499aca1
Compare
Signed-off-by: Lukas Schaefer <[email protected]>
499aca1 to
fb27767
Compare
Gemini complains about a list being passed as the arguments instead of an object. It has an unintended side effect that every single empty object/array will be turned into an empty object when json encoded as a function argument.