✨ (openai) Add tools and functions support (#1167)
Closes #863 Got helped from #1162 for the implementation. Closing it in favor of this PR. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced `CodeEditor` with additional properties for better form control and validation. - Introduced tools and functions in OpenAI integrations documentation for custom JavaScript execution. - Added capability to define and use custom JavaScript functions with the OpenAI assistant. - Expanded layout metadata options to include various input types and languages. - **Improvements** - Updated the OpenAI actions to support new function execution features. - **Documentation** - Added new sections for tools and functions in the OpenAI integrations guide. - **Refactor** - Refactored components and actions to integrate new features and improve existing functionalities. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/js",
|
||||
"version": "0.2.33",
|
||||
"version": "0.2.34",
|
||||
"description": "Javascript library to display typebots on your website",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
|
@ -90,27 +90,7 @@ export const ConversationContainer = (props: Props) => {
|
||||
const actionsBeforeFirstBubble = initialChunk.clientSideActions.filter(
|
||||
(action) => isNotDefined(action.lastBubbleBlockId)
|
||||
)
|
||||
for (const action of actionsBeforeFirstBubble) {
|
||||
if (
|
||||
'streamOpenAiChatCompletion' in action ||
|
||||
'webhookToExecute' in action
|
||||
)
|
||||
setIsSending(true)
|
||||
const response = await executeClientSideAction({
|
||||
clientSideAction: action,
|
||||
context: {
|
||||
apiHost: props.context.apiHost,
|
||||
sessionId: props.initialChatReply.sessionId,
|
||||
},
|
||||
onMessageStream: streamMessage,
|
||||
})
|
||||
if (response && 'replyToSend' in response) {
|
||||
sendMessage(response.replyToSend, response.logs)
|
||||
return
|
||||
}
|
||||
if (response && 'blockedPopupUrl' in response)
|
||||
setBlockedPopupUrl(response.blockedPopupUrl)
|
||||
}
|
||||
processClientSideActions(actionsBeforeFirstBubble)
|
||||
})()
|
||||
})
|
||||
|
||||
@ -210,27 +190,7 @@ export const ConversationContainer = (props: Props) => {
|
||||
const actionsBeforeFirstBubble = data.clientSideActions.filter((action) =>
|
||||
isNotDefined(action.lastBubbleBlockId)
|
||||
)
|
||||
for (const action of actionsBeforeFirstBubble) {
|
||||
if (
|
||||
'streamOpenAiChatCompletion' in action ||
|
||||
'webhookToExecute' in action
|
||||
)
|
||||
setIsSending(true)
|
||||
const response = await executeClientSideAction({
|
||||
clientSideAction: action,
|
||||
context: {
|
||||
apiHost: props.context.apiHost,
|
||||
sessionId: props.initialChatReply.sessionId,
|
||||
},
|
||||
onMessageStream: streamMessage,
|
||||
})
|
||||
if (response && 'replyToSend' in response) {
|
||||
sendMessage(response.replyToSend, response.logs)
|
||||
return
|
||||
}
|
||||
if (response && 'blockedPopupUrl' in response)
|
||||
setBlockedPopupUrl(response.blockedPopupUrl)
|
||||
}
|
||||
processClientSideActions(actionsBeforeFirstBubble)
|
||||
}
|
||||
setChatChunks((displayedChunks) => [
|
||||
...displayedChunks,
|
||||
@ -267,27 +227,35 @@ export const ConversationContainer = (props: Props) => {
|
||||
const actionsToExecute = lastChunk.clientSideActions.filter(
|
||||
(action) => action.lastBubbleBlockId === blockId
|
||||
)
|
||||
for (const action of actionsToExecute) {
|
||||
if (
|
||||
'streamOpenAiChatCompletion' in action ||
|
||||
'webhookToExecute' in action
|
||||
)
|
||||
setIsSending(true)
|
||||
const response = await executeClientSideAction({
|
||||
clientSideAction: action,
|
||||
context: {
|
||||
apiHost: props.context.apiHost,
|
||||
sessionId: props.initialChatReply.sessionId,
|
||||
},
|
||||
onMessageStream: streamMessage,
|
||||
})
|
||||
if (response && 'replyToSend' in response) {
|
||||
sendMessage(response.replyToSend, response.logs)
|
||||
return
|
||||
}
|
||||
if (response && 'blockedPopupUrl' in response)
|
||||
setBlockedPopupUrl(response.blockedPopupUrl)
|
||||
await processClientSideActions(actionsToExecute)
|
||||
}
|
||||
}
|
||||
|
||||
const processClientSideActions = async (
|
||||
actions: NonNullable<ContinueChatResponse['clientSideActions']>
|
||||
) => {
|
||||
for (const action of actions) {
|
||||
if (
|
||||
'streamOpenAiChatCompletion' in action ||
|
||||
'webhookToExecute' in action ||
|
||||
'stream' in action
|
||||
)
|
||||
setIsSending(true)
|
||||
const response = await executeClientSideAction({
|
||||
clientSideAction: action,
|
||||
context: {
|
||||
apiHost: props.context.apiHost,
|
||||
sessionId: props.initialChatReply.sessionId,
|
||||
},
|
||||
onMessageStream: streamMessage,
|
||||
})
|
||||
if (response && 'replyToSend' in response) {
|
||||
setIsSending(false)
|
||||
sendMessage(response.replyToSend, response.logs)
|
||||
return
|
||||
}
|
||||
if (response && 'blockedPopupUrl' in response)
|
||||
setBlockedPopupUrl(response.blockedPopupUrl)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/nextjs",
|
||||
"version": "0.2.33",
|
||||
"version": "0.2.34",
|
||||
"description": "Convenient library to display typebots on your Next.js website",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/react",
|
||||
"version": "0.2.33",
|
||||
"version": "0.2.34",
|
||||
"description": "Convenient library to display typebots on your React app",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
Reference in New Issue
Block a user