2
0
Files
bot/packages/forge/blocks/togetherAi/actions/createChatCompletion.tsx

59 lines
2.0 KiB
TypeScript
Raw Normal View History

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'
2024-07-15 14:32:42 +02:00
import { runOpenAIChatCompletion } from '@typebot.io/openai-block/shared/runOpenAIChatCompletion'
import { runOpenAIChatCompletionStream } from '@typebot.io/openai-block/shared/runOpenAIChatCompletionStream'
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-07-15 14:32:42 +02:00
defaultTemperature: defaultTogetherOptions.temperature,
}),
turnableInto: [
{
blockId: 'openai',
},
{
blockId: 'open-router',
},
{ blockId: 'mistral' },
{
blockId: 'anthropic',
transform: (options) => ({
...options,
action: 'Create Chat Message',
responseMapping: options.responseMapping?.map((res: any) =>
res.item === 'Message content'
? { ...res, item: 'Message Content' }
: res
),
}),
},
2024-08-22 15:31:05 +02:00
{ blockId: 'groq' },
],
getSetVariableIds: getChatCompletionSetVarIds,
run: {
server: (params) =>
2024-07-15 14:32:42 +02:00
runOpenAIChatCompletion({
...params,
config: { baseUrl: defaultTogetherOptions.baseUrl },
}),
stream: {
getStreamVariableId: getChatCompletionStreamVarId,
2024-07-15 14:32:42 +02:00
run: async (params) =>
runOpenAIChatCompletionStream({
...params,
2024-07-15 14:32:42 +02:00
config: {
baseUrl: defaultTogetherOptions.baseUrl,
},
}),
},
},
})