Skip to content

Arguments for tool calls are encoded incorrectly #244

Description

@lukasdotcom

Which version of integration_openai are you using?

3.7.1

Which version of Nextcloud are you using?

32

Which browser are you using? In case you are using the phone App, specify the Android or iOS version and device please.

No response

Describe the Bug

When the encoding of the arguments happens it can cause a problem when the argument is an empty object {} it can be reencoded as []

if ($history !== null) {
foreach ($history as $i => $historyEntry) {
$message = json_decode($historyEntry, true);
if ($message['role'] === 'human') {
$message['role'] = 'user';
}
if (isset($message['tool_calls']) && is_array($message['tool_calls'])) {
$message['tool_calls'] = array_map(static function ($toolCall) {
$formattedToolCall = [
'id' => $toolCall['id'],
'type' => 'function',
'function' => $toolCall,
];
$formattedToolCall['function']['arguments'] = json_encode($toolCall['args']);
unset($formattedToolCall['function']['id']);
unset($formattedToolCall['function']['args']);
unset($formattedToolCall['function']['type']);
return $formattedToolCall;
}, $message['tool_calls']);

I did make a draft pr, but it has unintended side effects at: #243

Expected Behavior

^

To Reproduce

Get tool call that has no arguments. Ex: list current user information

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions