2
0

⬆️ Upgrade AI SDK (#1641)

This commit is contained in:
Baptiste Arnaud
2024-07-15 14:32:42 +02:00
committed by GitHub
parent a4fb8b6d10
commit 043f0054b0
60 changed files with 2183 additions and 1683 deletions

View File

@@ -1,6 +1,7 @@
import { option } from '@typebot.io/forge'
import { z } from '@typebot.io/forge/zod'
import { baseOptions } from '../baseOptions'
import { toolsSchema } from '@typebot.io/ai/schemas'
const nativeMessageContentSchema = {
content: option.string.layout({
@@ -27,77 +28,6 @@ const assistantMessageItemSchema = option
})
.extend(nativeMessageContentSchema)
const parameterBase = {
name: option.string.layout({
label: 'Name',
placeholder: 'myVariable',
withVariableButton: false,
}),
description: option.string.layout({
label: 'Description',
withVariableButton: false,
}),
required: option.boolean.layout({
label: 'Is required?',
}),
}
export const toolParametersSchema = option
.array(
option.discriminatedUnion('type', [
option
.object({
type: option.literal('string'),
})
.extend(parameterBase),
option
.object({
type: option.literal('number'),
})
.extend(parameterBase),
option
.object({
type: option.literal('boolean'),
})
.extend(parameterBase),
option
.object({
type: option.literal('enum'),
values: option
.array(option.string)
.layout({ itemLabel: 'possible value' }),
})
.extend(parameterBase),
])
)
.layout({
accordion: 'Parameters',
itemLabel: 'parameter',
})
const functionToolItemSchema = option.object({
type: option.literal('function'),
name: option.string.layout({
label: 'Name',
placeholder: 'myFunctionName',
withVariableButton: false,
}),
description: option.string.layout({
label: 'Description',
placeholder: 'A brief description of what this function does.',
withVariableButton: false,
}),
parameters: toolParametersSchema,
code: option.string.layout({
inputType: 'code',
label: 'Code',
lang: 'javascript',
moreInfoTooltip:
'A javascript code snippet that can use the defined parameters. It should return a value.',
withVariableButton: false,
}),
})
const dialogueMessageItemSchema = option.object({
role: option.literal('Dialogue'),
dialogueVariableId: option.string.layout({
@@ -112,23 +42,20 @@ const dialogueMessageItemSchema = option.object({
})
type Props = {
defaultModel?: string
defaultTemperature?: number
defaultTemperature: number
modelFetchId?: string
modelHelperText?: string
}
export const parseChatCompletionOptions = ({
defaultModel,
defaultTemperature,
modelFetchId,
modelHelperText,
}: Props = {}) =>
}: Props) =>
option.object({
model: option.string.layout({
placeholder: modelFetchId ? 'Select a model' : undefined,
label: modelFetchId ? undefined : 'Model',
defaultValue: defaultModel,
fetcher: modelFetchId,
helperText: modelHelperText,
}),
@@ -142,9 +69,7 @@ export const parseChatCompletionOptions = ({
])
)
.layout({ accordion: 'Messages', itemLabel: 'message', isOrdered: true }),
tools: option
.array(option.discriminatedUnion('type', [functionToolItemSchema]))
.layout({ accordion: 'Tools', itemLabel: 'tool' }),
tools: toolsSchema,
temperature: option.number.layout({
accordion: 'Advanced settings',
label: 'Temperature',