From 59439dbaa087106c40df1d7cabcd5c3f0db05898 Mon Sep 17 00:00:00 2001 From: Dario Gieselaar Date: Mon, 10 Jun 2024 10:44:55 +0200 Subject: [PATCH] [Obs AI Assistant] Make sure arguments have a default --- .../server/service/client/adapters/openai_adapter.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/observability_solution/observability_ai_assistant/server/service/client/adapters/openai_adapter.ts b/x-pack/plugins/observability_solution/observability_ai_assistant/server/service/client/adapters/openai_adapter.ts index 01b8fcb3b5923..bcb9b25ab686c 100644 --- a/x-pack/plugins/observability_solution/observability_ai_assistant/server/service/client/adapters/openai_adapter.ts +++ b/x-pack/plugins/observability_solution/observability_ai_assistant/server/service/client/adapters/openai_adapter.ts @@ -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; })