2024-03-01 15:33:22 +01:00
import { createAction } from '@typebot.io/forge'
import { auth } from '../auth'
import { parseChatCompletionOptions } from '@typebot.io/openai-block/shared/parseChatCompletionOptions'
import { getChatCompletionSetVarIds } from '@typebot.io/openai-block/shared/getChatCompletionSetVarIds'
import { getChatCompletionStreamVarId } from '@typebot.io/openai-block/shared/getChatCompletionStreamVarId'
import { runChatCompletion } from '@typebot.io/openai-block/shared/runChatCompletion'
import { runChatCompletionStream } from '@typebot.io/openai-block/shared/runChatCompletionStream'
import { defaultTogetherOptions } from '../constants'
export const createChatCompletion = createAction ( {
name : 'Create chat completion' ,
auth ,
options : parseChatCompletionOptions ( {
modelHelperText :
'You can find the list of all the models available [here](https://docs.together.ai/docs/inference-models#chat-models). Copy the model string for API.' ,
} ) ,
2024-03-05 15:46:28 +01:00
turnableInto : [
{
blockType : 'openai' ,
} ,
{
blockType : 'open-router' ,
} ,
{ blockType : 'mistral' } ,
2024-03-15 14:17:06 +01:00
{
blockType : 'anthropic' ,
transform : ( options ) = > ( {
. . . options ,
action : 'Create Chat Message' ,
2024-03-15 15:13:54 +01:00
responseMapping : options.responseMapping?.map ( ( res : any ) = >
res . item === 'Message content'
? { . . . res , item : 'Message Content' }
: res
) ,
2024-03-15 14:17:06 +01:00
} ) ,
} ,
2024-03-05 15:46:28 +01:00
] ,
2024-03-01 15:33:22 +01:00
getSetVariableIds : getChatCompletionSetVarIds ,
run : {
server : ( params ) = >
runChatCompletion ( {
. . . params ,
config : { baseUrl : defaultTogetherOptions.baseUrl } ,
} ) ,
stream : {
getStreamVariableId : getChatCompletionStreamVarId ,
run : ( params ) = >
runChatCompletionStream ( {
. . . params ,
config : { baseUrl : defaultTogetherOptions.baseUrl } ,
} ) ,
} ,
} ,
} )