Empty argument gets encoded as [] instead of {}#243
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.
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.
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.
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.
That also isn't always wanted because I think it is possible to pass an empty array as an argument like below.
{"features":[]}0324fc6 to
499aca1
Compare
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
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.