-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
173 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/forge/blocks/openRouter/actions/createChatCompletion.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }, | ||
}), | ||
}, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const defaultOpenRouterOptions = { | ||
baseUrl: 'https://openrouter.ai/api/v1', | ||
} as const |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "@typebot.io/tsconfig/base.json", | ||
"include": ["**/*.ts", "**/*.tsx"], | ||
"exclude": ["node_modules"], | ||
"compilerOptions": { | ||
"lib": ["ESNext", "DOM"], | ||
"noEmit": true, | ||
"jsx": "react" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type ModelsResponse = { | ||
data: { | ||
id: string | ||
name: string | ||
}[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ export const enabledBlocks = [ | |
'mistral', | ||
'elevenlabs', | ||
'together-ai', | ||
'open-router', | ||
] as const |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.