[8.14] [Obs AI Assistant] Make sure arguments have a default (#185691) (#188655)

# Backport

This will backport the following commits from `main` to `8.14`:
- [[Obs AI Assistant] Make sure arguments have a default
(#185691)](https://github.com/elastic/kibana/pull/185691)

<!--- Backport version: 7.3.2 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT {commits} BACKPORT-->

Co-authored-by: Sandra G <neptunian@users.noreply.github.com>
This commit is contained in:
Dario Gieselaar 2024-07-23 16:06:38 +02:00 committed by GitHub
parent a3a1efbb01
commit 669df43b88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;
})