2023-03-09 08:46:36 +01:00
|
|
|
import { ExecuteIntegrationResponse } from '@/features/chat/types'
|
2023-03-15 08:35:16 +01:00
|
|
|
import { SessionState } from '@typebot.io/schemas'
|
|
|
|
|
import { OpenAIBlock } from '@typebot.io/schemas/features/blocks/integrations/openai'
|
2023-03-09 08:46:36 +01:00
|
|
|
import { createChatCompletionOpenAI } from './createChatCompletionOpenAI'
|
|
|
|
|
|
|
|
|
|
export const executeOpenAIBlock = async (
|
|
|
|
|
state: SessionState,
|
|
|
|
|
block: OpenAIBlock
|
|
|
|
|
): Promise<ExecuteIntegrationResponse> => {
|
|
|
|
|
switch (block.options.task) {
|
|
|
|
|
case 'Create chat completion':
|
|
|
|
|
return createChatCompletionOpenAI(state, {
|
|
|
|
|
options: block.options,
|
|
|
|
|
outgoingEdgeId: block.outgoingEdgeId,
|
|
|
|
|
})
|
|
|
|
|
case 'Create image':
|
|
|
|
|
case undefined:
|
|
|
|
|
return { outgoingEdgeId: block.outgoingEdgeId }
|
|
|
|
|
}
|
|
|
|
|
}
|