🐛 (openai) Fix ask assistant not correctly referencing uploaded f… (#1469)
…iles Closes #1468, closes #1467, closes #1211
This commit is contained in:
@ -3,7 +3,7 @@ import { ChatCompletionOpenAIOptions } from '@typebot.io/schemas/features/blocks
|
||||
import { OpenAI } from 'openai'
|
||||
import { decryptV2 } from '@typebot.io/lib/api/encryption/decryptV2'
|
||||
import { forgedBlocks } from '@typebot.io/forge-repository/definitions'
|
||||
import { ReadOnlyVariableStore } from '@typebot.io/forge'
|
||||
import { VariableStore } from '@typebot.io/forge'
|
||||
import {
|
||||
ParseVariablesOptions,
|
||||
parseVariables,
|
||||
@ -13,6 +13,9 @@ import { getCredentials } from '../queries/getCredentials'
|
||||
import { getSession } from '../queries/getSession'
|
||||
import { getBlockById } from '@typebot.io/schemas/helpers'
|
||||
import { isForgedBlockType } from '@typebot.io/schemas/features/blocks/forged/helpers'
|
||||
import { updateVariablesInSession } from '@typebot.io/variables/updateVariablesInSession'
|
||||
import { updateSession } from '../queries/updateSession'
|
||||
import { deepParseVariables } from '@typebot.io/variables/deepParseVariables'
|
||||
|
||||
type Props = {
|
||||
sessionId: string
|
||||
@ -92,7 +95,8 @@ export const getMessageStream = async ({ sessionId, messages }: Props) => {
|
||||
credentials.data,
|
||||
credentials.iv
|
||||
)
|
||||
const variables: ReadOnlyVariableStore = {
|
||||
|
||||
const variables: VariableStore = {
|
||||
list: () => session.state.typebotsQueue[0].typebot.variables,
|
||||
get: (id: string) => {
|
||||
const variable = session.state.typebotsQueue[0].typebot.variables.find(
|
||||
@ -105,10 +109,25 @@ export const getMessageStream = async ({ sessionId, messages }: Props) => {
|
||||
session.state.typebotsQueue[0].typebot.variables,
|
||||
params
|
||||
)(text),
|
||||
set: async (id: string, value: unknown) => {
|
||||
const variable = session.state.typebotsQueue[0].typebot.variables.find(
|
||||
(variable) => variable.id === id
|
||||
)
|
||||
if (!variable) return
|
||||
await updateSession({
|
||||
id: session.id,
|
||||
state: updateVariablesInSession(session.state)([
|
||||
{ ...variable, value },
|
||||
]),
|
||||
isReplying: undefined,
|
||||
})
|
||||
},
|
||||
}
|
||||
const stream = await action.run.stream.run({
|
||||
credentials: decryptedCredentials,
|
||||
options: block.options,
|
||||
options: deepParseVariables(
|
||||
session.state.typebotsQueue[0].typebot.variables
|
||||
)(block.options),
|
||||
variables,
|
||||
})
|
||||
if (!stream) return { status: 500, message: 'Could not create stream' }
|
||||
|
@ -89,9 +89,7 @@ export const createChatCompletionOpenAI = async (
|
||||
isNextBubbleMessageWithAssistantMessage(typebot)(
|
||||
blockId,
|
||||
assistantMessageVariableName
|
||||
) &&
|
||||
(!process.env.VERCEL_ENV ||
|
||||
(isPlaneteScale() && credentials && isCredentialsV2(credentials)))
|
||||
)
|
||||
) {
|
||||
return {
|
||||
clientSideActions: [
|
||||
@ -102,7 +100,6 @@ export const createChatCompletionOpenAI = async (
|
||||
content?: string
|
||||
role: (typeof chatCompletionMessageRoles)[number]
|
||||
}[],
|
||||
runtime: process.env.VERCEL_ENV ? 'edge' : 'nodejs',
|
||||
},
|
||||
expectsDedicatedReply: true,
|
||||
},
|
||||
|
@ -58,9 +58,7 @@ export const executeForgedBlock = async (
|
||||
action.run.stream.getStreamVariableId(block.options)
|
||||
) &&
|
||||
state.isStreamEnabled &&
|
||||
!state.whatsApp &&
|
||||
(!process.env.VERCEL_ENV ||
|
||||
(isPlaneteScale() && credentials && isCredentialsV2(credentials)))
|
||||
!state.whatsApp
|
||||
) {
|
||||
return {
|
||||
outgoingEdgeId: block.outgoingEdgeId,
|
||||
@ -69,7 +67,6 @@ export const executeForgedBlock = async (
|
||||
type: 'stream',
|
||||
expectsDedicatedReply: true,
|
||||
stream: true,
|
||||
runtime: process.env.VERCEL_ENV ? 'edge' : 'nodejs',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
"@typebot.io/tsconfig": "workspace:*",
|
||||
"@typebot.io/variables": "workspace:*",
|
||||
"@udecode/plate-common": "30.4.5",
|
||||
"ai": "3.0.12",
|
||||
"ai": "3.0.31",
|
||||
"chrono-node": "2.7.5",
|
||||
"date-fns": "2.30.0",
|
||||
"date-fns-tz": "2.0.0",
|
||||
@ -29,7 +29,7 @@
|
||||
"libphonenumber-js": "1.10.37",
|
||||
"node-html-parser": "6.1.5",
|
||||
"nodemailer": "6.9.8",
|
||||
"openai": "4.28.4",
|
||||
"openai": "4.38.3",
|
||||
"qs": "6.11.2",
|
||||
"stripe": "12.13.0"
|
||||
},
|
||||
|
@ -5,7 +5,7 @@ import { SessionState } from '@typebot.io/schemas'
|
||||
type Props = {
|
||||
id: string
|
||||
state: SessionState
|
||||
isReplying: boolean
|
||||
isReplying: boolean | undefined
|
||||
}
|
||||
|
||||
export const updateSession = ({
|
||||
|
Reference in New Issue
Block a user