mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Obs AI Assistant] Make sure arguments have a default (#185691)
In https://github.com/elastic/kibana/pull/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.
This commit is contained in:
parent
8119aac0fe
commit
8f3359c43d
1 changed files with 7 additions and 4 deletions
|
@ -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';
|
||||
|
@ -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;
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue