Skip to content

Commit

Permalink
[Obs AI Assistant] Make sure arguments have a default (elastic#185691)
Browse files Browse the repository at this point in the history
In elastic#184933, we removed the
parameters for the `context` function, however, OpenAI requires at least
an empty `arguments` object, so requests fail. This PR sets arguments to
an empty JSON object (`"{}"`) if `function_call.arguments` is empty.

(cherry picked from commit 8f3359c)
  • Loading branch information
dgieselaar committed Jul 18, 2024
1 parent 8da7b1d commit d63b236
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { encode } from 'gpt-tokenizer';
import { compact, isEmpty, merge, omit, pick } from 'lodash';
import { compact, merge, pick } from 'lodash';
import OpenAI from 'openai';
import { identity } from 'rxjs';
import { CompatibleJSONSchema } from '../../../../common/functions/types';
Expand Down Expand Up @@ -68,9 +68,12 @@ function messagesToOpenAI(messages: Message[]): OpenAI.ChatCompletionMessagePara
return {
role,
content: message.message.content,
function_call: isEmpty(message.message.function_call?.name)
? undefined
: omit(message.message.function_call, 'trigger'),
function_call: message.message.function_call?.name
? {
name: message.message.function_call.name,
arguments: message.message.function_call?.arguments || '{}',
}
: undefined,
name: message.message.name,
} as OpenAI.ChatCompletionMessageParam;
})
Expand Down

0 comments on commit d63b236

Please sign in to comment.