@ -18793,7 +18793,8 @@
|
||||
"dify-ai",
|
||||
"mistral",
|
||||
"elevenlabs",
|
||||
"together-ai"
|
||||
"together-ai",
|
||||
"open-router"
|
||||
]
|
||||
},
|
||||
"options": {}
|
||||
|
@ -9414,7 +9414,8 @@
|
||||
"dify-ai",
|
||||
"mistral",
|
||||
"elevenlabs",
|
||||
"together-ai"
|
||||
"together-ai",
|
||||
"open-router"
|
||||
]
|
||||
},
|
||||
"options": {}
|
||||
|
@ -0,0 +1,50 @@
|
||||
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 { defaultOpenRouterOptions } from '../constants'
|
||||
import { got } from 'got'
|
||||
import { ModelsResponse } from '../types'
|
||||
|
||||
export const createChatCompletion = createAction({
|
||||
name: 'Create chat completion',
|
||||
auth,
|
||||
options: parseChatCompletionOptions({
|
||||
modelFetchId: 'fetchModels',
|
||||
}),
|
||||
getSetVariableIds: getChatCompletionSetVarIds,
|
||||
fetchers: [
|
||||
{
|
||||
id: 'fetchModels',
|
||||
dependencies: [],
|
||||
fetch: async () => {
|
||||
const response = await got
|
||||
.get(defaultOpenRouterOptions.baseUrl + '/models')
|
||||
.json<ModelsResponse>()
|
||||
|
||||
return response.data.map((model) => ({
|
||||
value: model.id,
|
||||
label: model.name,
|
||||
}))
|
||||
},
|
||||
},
|
||||
],
|
||||
run: {
|
||||
server: (params) =>
|
||||
runChatCompletion({
|
||||
...params,
|
||||
config: { baseUrl: defaultOpenRouterOptions.baseUrl },
|
||||
}),
|
||||
stream: {
|
||||
getStreamVariableId: getChatCompletionStreamVarId,
|
||||
run: (params) =>
|
||||
runChatCompletionStream({
|
||||
...params,
|
||||
config: { baseUrl: defaultOpenRouterOptions.baseUrl },
|
||||
}),
|
||||
},
|
||||
},
|
||||
})
|
15
packages/forge/blocks/openRouter/auth.ts
Normal file
15
packages/forge/blocks/openRouter/auth.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { option, AuthDefinition } from '@typebot.io/forge'
|
||||
|
||||
export const auth = {
|
||||
type: 'encryptedCredentials',
|
||||
name: 'OpenRouter account',
|
||||
schema: option.object({
|
||||
apiKey: option.string.layout({
|
||||
label: 'API key',
|
||||
isRequired: true,
|
||||
inputType: 'password',
|
||||
helperText:
|
||||
'You can generate an API key [here](https://openrouter.ai/keys).',
|
||||
}),
|
||||
}),
|
||||
} satisfies AuthDefinition
|
3
packages/forge/blocks/openRouter/constants.ts
Normal file
3
packages/forge/blocks/openRouter/constants.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export const defaultOpenRouterOptions = {
|
||||
baseUrl: 'https://openrouter.ai/api/v1',
|
||||
} as const
|
13
packages/forge/blocks/openRouter/index.ts
Normal file
13
packages/forge/blocks/openRouter/index.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { createBlock } from '@typebot.io/forge'
|
||||
import { OpenRouterLogo } from './logo'
|
||||
import { auth } from './auth'
|
||||
import { createChatCompletion } from './actions/createChatCompletion'
|
||||
|
||||
export const openRouter = createBlock({
|
||||
id: 'open-router',
|
||||
name: 'OpenRouter',
|
||||
tags: ['ai', 'openai', 'chat', 'completion'],
|
||||
LightLogo: OpenRouterLogo,
|
||||
auth,
|
||||
actions: [createChatCompletion],
|
||||
})
|
23
packages/forge/blocks/openRouter/logo.tsx
Normal file
23
packages/forge/blocks/openRouter/logo.tsx
Normal file
@ -0,0 +1,23 @@
|
||||
import React from 'react'
|
||||
|
||||
export const OpenRouterLogo = (props: React.SVGProps<SVGSVGElement>) => (
|
||||
<svg viewBox="0 0 512 512" fill="#71717A" stroke="#71717A" {...props}>
|
||||
<g clip-path="url(#clip0_205_3)">
|
||||
<path
|
||||
d="M3 248.945C18 248.945 76 236 106 219C136 202 136 202 198 158C276.497 102.293 332 120.945 423 120.945"
|
||||
strokeWidth="90"
|
||||
></path>
|
||||
<path d="M511 121.5L357.25 210.268L357.25 32.7324L511 121.5Z"></path>
|
||||
<path
|
||||
d="M0 249C15 249 73 261.945 103 278.945C133 295.945 133 295.945 195 339.945C273.497 395.652 329 377 420 377"
|
||||
strokeWidth="90"
|
||||
></path>
|
||||
<path d="M508 376.445L354.25 287.678L354.25 465.213L508 376.445Z"></path>
|
||||
</g>
|
||||
<defs>
|
||||
<clipPath id="clip0_205_3">
|
||||
<rect width="512" height="512"></rect>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
)
|
17
packages/forge/blocks/openRouter/package.json
Normal file
17
packages/forge/blocks/openRouter/package.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@typebot.io/open-router-block",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.ts",
|
||||
"keywords": [],
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@typebot.io/forge": "workspace:*",
|
||||
"@typebot.io/tsconfig": "workspace:*",
|
||||
"@types/react": "18.2.15",
|
||||
"typescript": "5.3.2",
|
||||
"@typebot.io/lib": "workspace:*",
|
||||
"@typebot.io/openai-block": "workspace:*",
|
||||
"got": "12.6.0"
|
||||
}
|
||||
}
|
10
packages/forge/blocks/openRouter/tsconfig.json
Normal file
10
packages/forge/blocks/openRouter/tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "@typebot.io/tsconfig/base.json",
|
||||
"include": ["**/*.ts", "**/*.tsx"],
|
||||
"exclude": ["node_modules"],
|
||||
"compilerOptions": {
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"noEmit": true,
|
||||
"jsx": "react"
|
||||
}
|
||||
}
|
6
packages/forge/blocks/openRouter/types.ts
Normal file
6
packages/forge/blocks/openRouter/types.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export type ModelsResponse = {
|
||||
data: {
|
||||
id: string
|
||||
name: string
|
||||
}[]
|
||||
}
|
@ -9,4 +9,5 @@ export const enabledBlocks = [
|
||||
'mistral',
|
||||
'elevenlabs',
|
||||
'together-ai',
|
||||
'open-router',
|
||||
] as const
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Do not edit this file manually
|
||||
import { openRouter } from '@typebot.io/open-router-block'
|
||||
import { togetherAi } from '@typebot.io/together-ai-block'
|
||||
import { elevenlabs } from '@typebot.io/elevenlabs-block'
|
||||
import { difyAi } from '@typebot.io/dify-ai-block'
|
||||
@ -26,6 +27,7 @@ export const forgedBlocks = [
|
||||
mistral,
|
||||
elevenlabs,
|
||||
togetherAi,
|
||||
openRouter,
|
||||
] as BlockDefinition<(typeof enabledBlocks)[number], any, any>[]
|
||||
|
||||
export type ForgedBlockDefinition = (typeof forgedBlocks)[number]
|
||||
|
@ -17,6 +17,7 @@
|
||||
"@typebot.io/dify-ai-block": "workspace:*",
|
||||
"@typebot.io/mistral-block": "workspace:*",
|
||||
"@typebot.io/elevenlabs-block": "workspace:*",
|
||||
"@typebot.io/together-ai-block": "workspace:*"
|
||||
"@typebot.io/together-ai-block": "workspace:*",
|
||||
"@typebot.io/open-router-block": "workspace:*"
|
||||
}
|
||||
}
|
||||
|
27
pnpm-lock.yaml
generated
27
pnpm-lock.yaml
generated
@ -1268,6 +1268,30 @@ importers:
|
||||
specifier: 5.3.2
|
||||
version: 5.3.2
|
||||
|
||||
packages/forge/blocks/openRouter:
|
||||
devDependencies:
|
||||
'@typebot.io/forge':
|
||||
specifier: workspace:*
|
||||
version: link:../../core
|
||||
'@typebot.io/lib':
|
||||
specifier: workspace:*
|
||||
version: link:../../../lib
|
||||
'@typebot.io/openai-block':
|
||||
specifier: workspace:*
|
||||
version: link:../openai
|
||||
'@typebot.io/tsconfig':
|
||||
specifier: workspace:*
|
||||
version: link:../../../tsconfig
|
||||
'@types/react':
|
||||
specifier: 18.2.15
|
||||
version: 18.2.15
|
||||
got:
|
||||
specifier: 12.6.0
|
||||
version: 12.6.0
|
||||
typescript:
|
||||
specifier: 5.3.2
|
||||
version: 5.3.2
|
||||
|
||||
packages/forge/blocks/openai:
|
||||
dependencies:
|
||||
ai:
|
||||
@ -1422,6 +1446,9 @@ importers:
|
||||
'@typebot.io/mistral-block':
|
||||
specifier: workspace:*
|
||||
version: link:../blocks/mistral
|
||||
'@typebot.io/open-router-block':
|
||||
specifier: workspace:*
|
||||
version: link:../blocks/openRouter
|
||||
'@typebot.io/openai-block':
|
||||
specifier: workspace:*
|
||||
version: link:../blocks/openai
|
||||
|
Reference in New Issue
Block a user