2
0

(openai) Add enum support in function tools

This commit is contained in:
Baptiste Arnaud
2024-01-29 14:45:44 +01:00
parent 4b8b80e996
commit 8d363c0c02
5 changed files with 106 additions and 64 deletions

View File

@@ -1,9 +1,9 @@
import type { OpenAI } from 'openai'
import { parameterSchema } from '../actions/createChatCompletion'
import { toolParametersSchema } from '../actions/createChatCompletion'
import { z } from '@typebot.io/forge/zod'
export const parseToolParameters = (
parameters: z.infer<typeof parameterSchema>[]
parameters: z.infer<typeof toolParametersSchema>
): OpenAI.FunctionParameters => ({
type: 'object',
properties: parameters?.reduce<{
@@ -11,7 +11,8 @@ export const parseToolParameters = (
}>((acc, param) => {
if (!param.name) return acc
acc[param.name] = {
type: param.type,
type: param.type === 'enum' ? 'string' : param.type,
enum: param.type === 'enum' ? param.values : undefined,
description: param.description,
}
return acc