fix OpenAi function calling with optional parameters
This commit is contained in:
@ -214,13 +214,16 @@ export const createChatCompletion = createAction({
|
|||||||
if (!name) continue
|
if (!name) continue
|
||||||
const toolDefinition = options.tools?.find((t) => t.name === name)
|
const toolDefinition = options.tools?.find((t) => t.name === name)
|
||||||
if (!toolDefinition?.code || !toolDefinition.parameters) continue
|
if (!toolDefinition?.code || !toolDefinition.parameters) continue
|
||||||
|
const toolParams = Object.fromEntries(
|
||||||
|
toolDefinition.parameters.map(({ name }) => [name, null])
|
||||||
|
)
|
||||||
const toolArgs = toolCall.function?.arguments
|
const toolArgs = toolCall.function?.arguments
|
||||||
? JSON.parse(toolCall.function?.arguments)
|
? JSON.parse(toolCall.function?.arguments)
|
||||||
: undefined
|
: undefined
|
||||||
if (!toolArgs) continue
|
if (!toolArgs) continue
|
||||||
const { output, newVariables } = await executeFunction({
|
const { output, newVariables } = await executeFunction({
|
||||||
variables: variables.list(),
|
variables: variables.list(),
|
||||||
args: toolArgs,
|
args: { ...toolParams, ...toolArgs },
|
||||||
body: toolDefinition.code,
|
body: toolDefinition.code,
|
||||||
})
|
})
|
||||||
newVariables?.forEach((v) => variables.set(v.id, v.value))
|
newVariables?.forEach((v) => variables.set(v.id, v.value))
|
||||||
|
Reference in New Issue
Block a user