2
0

(openai) Add "Ask assistant" action

Closes #1024
This commit is contained in:
Baptiste Arnaud
2024-01-11 08:29:41 +01:00
parent 799c694522
commit 03258e0f64
13 changed files with 257 additions and 42 deletions

View File

@@ -76,7 +76,7 @@
"nextjs-cors": "2.1.2",
"nodemailer": "6.9.3",
"nprogress": "0.2.0",
"openai": "4.19.0",
"openai": "4.24.1",
"papaparse": "5.4.1",
"posthog-js": "1.77.1",
"posthog-node": "3.1.1",

View File

@@ -12,7 +12,10 @@ type Props = {
onOptionsChange: (options: BlockOptions) => void
}
export const ForgedBlockSettings = ({ block, onOptionsChange }: Props) => {
const { blockDef, blockSchema } = useForgedBlock(block.type)
const { blockDef, blockSchema, actionDef } = useForgedBlock(
block.type,
block.options?.action
)
const { isOpen, onOpen, onClose } = useDisclosure()
const updateCredentialsId = (credentialsId?: string) => {
@@ -22,6 +25,34 @@ export const ForgedBlockSettings = ({ block, onOptionsChange }: Props) => {
})
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const resetOptionsAction = (updates: any) => {
if (!actionDef) return
const actionOptionsKeys = Object.keys(actionDef.options?.shape ?? [])
const actionOptions = actionOptionsKeys.reduce(
(acc, key) => ({
...acc,
[key]: undefined,
}),
{}
)
onOptionsChange({
...updates,
...actionOptions,
})
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const updateOptions = (updates: any) => {
const isChangingAction =
actionDef && updates?.action && updates.action !== block.options.action
if (isChangingAction) {
resetOptionsAction(updates)
return
}
onOptionsChange(updates)
}
if (!blockDef || !blockSchema) return null
return (
<Stack spacing={4}>
@@ -57,7 +88,7 @@ export const ForgedBlockSettings = ({ block, onOptionsChange }: Props) => {
schema={blockSchema.shape.options}
blockDef={blockDef}
blockOptions={block.options}
onDataChange={onOptionsChange}
onDataChange={updateOptions}
/>
</>
)}

View File

@@ -33,6 +33,17 @@ Then you can give the OpenAI block access to this sequence of messages:
/>
</Frame>
## Ask assistant
This action allows you to talk with your [OpenAI assistant](https://platform.openai.com/assistants). All you have to do is to provide its ID.
<Frame>
<img
src="/images/blocks/integrations/openai/ask-assistant.png"
alt="OpenAI ask assistant settings"
/>
</Frame>
## Create speech
This action allows you to transform a text input into an audio URL that you can reuse in your bot.

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

View File

@@ -26820,7 +26820,8 @@
"openai",
"zemantic-ai",
"cal-com",
"chat-node"
"chat-node",
"qr-code"
]
},
"options": {}

View File

@@ -10289,7 +10289,8 @@
"openai",
"zemantic-ai",
"cal-com",
"chat-node"
"chat-node",
"qr-code"
]
},
"options": {}

View File

@@ -20,7 +20,7 @@
"@typebot.io/js": "workspace:*",
"@typebot.io/nextjs": "workspace:*",
"@typebot.io/prisma": "workspace:*",
"ai": "2.2.24",
"ai": "2.2.31",
"bot-engine": "workspace:*",
"cors": "2.8.5",
"google-spreadsheet": "4.0.2",
@@ -28,7 +28,7 @@
"next": "14.0.3",
"nextjs-cors": "2.1.2",
"nodemailer": "6.9.3",
"openai": "4.19.0",
"openai": "4.24.1",
"qs": "6.11.2",
"react": "18.2.0",
"react-dom": "18.2.0",