⚡️(openai) Allow for custom base URL when adding new creds
Closes #1665
This commit is contained in:
@ -57,7 +57,7 @@ export const createChatCompletion = createAction({
|
|||||||
runOpenAIChatCompletion({
|
runOpenAIChatCompletion({
|
||||||
...params,
|
...params,
|
||||||
config: {
|
config: {
|
||||||
baseUrl: defaultOpenAIOptions.baseUrl,
|
baseUrl: params.credentials.baseUrl,
|
||||||
defaultModel: defaultOpenAIOptions.model,
|
defaultModel: defaultOpenAIOptions.model,
|
||||||
},
|
},
|
||||||
compatibility: 'strict',
|
compatibility: 'strict',
|
||||||
@ -68,7 +68,7 @@ export const createChatCompletion = createAction({
|
|||||||
runOpenAIChatCompletionStream({
|
runOpenAIChatCompletionStream({
|
||||||
...params,
|
...params,
|
||||||
config: {
|
config: {
|
||||||
baseUrl: defaultOpenAIOptions.baseUrl,
|
baseUrl: params.credentials.baseUrl,
|
||||||
defaultModel: defaultOpenAIOptions.model,
|
defaultModel: defaultOpenAIOptions.model,
|
||||||
},
|
},
|
||||||
compatibility: 'strict',
|
compatibility: 'strict',
|
||||||
|
@ -39,10 +39,10 @@ export const createSpeech = createAction({
|
|||||||
fetch: async ({ credentials, options }) => {
|
fetch: async ({ credentials, options }) => {
|
||||||
if (!credentials?.apiKey) return []
|
if (!credentials?.apiKey) return []
|
||||||
|
|
||||||
const baseUrl = options?.baseUrl ?? defaultOpenAIOptions.baseUrl
|
const baseUrl = options?.baseUrl
|
||||||
const config = {
|
const config = {
|
||||||
apiKey: credentials.apiKey,
|
apiKey: credentials.apiKey,
|
||||||
baseURL: baseUrl ?? defaultOpenAIOptions.baseUrl,
|
baseURL: baseUrl,
|
||||||
defaultHeaders: {
|
defaultHeaders: {
|
||||||
'api-key': credentials.apiKey,
|
'api-key': credentials.apiKey,
|
||||||
},
|
},
|
||||||
@ -75,7 +75,7 @@ export const createSpeech = createAction({
|
|||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
apiKey,
|
apiKey,
|
||||||
baseURL: options.baseUrl ?? defaultOpenAIOptions.baseUrl,
|
baseURL: options.baseUrl,
|
||||||
defaultHeaders: {
|
defaultHeaders: {
|
||||||
'api-key': apiKey,
|
'api-key': apiKey,
|
||||||
},
|
},
|
||||||
|
@ -29,7 +29,7 @@ export const createTranscription = createAction({
|
|||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
apiKey,
|
apiKey,
|
||||||
baseURL: options.baseUrl ?? defaultOpenAIOptions.baseUrl,
|
baseURL: options.baseUrl,
|
||||||
defaultHeaders: {
|
defaultHeaders: {
|
||||||
'api-key': apiKey,
|
'api-key': apiKey,
|
||||||
},
|
},
|
||||||
|
@ -14,5 +14,11 @@ export const auth = createAuth({
|
|||||||
withVariableButton: false,
|
withVariableButton: false,
|
||||||
isDebounceDisabled: true,
|
isDebounceDisabled: true,
|
||||||
}),
|
}),
|
||||||
|
baseUrl: option.string.layout({
|
||||||
|
label: 'Base URL',
|
||||||
|
defaultValue: 'https://api.openai.com/v1',
|
||||||
|
moreInfoTooltip:
|
||||||
|
'Use a different URL prefix for API calls, e.g. to use proxy servers.',
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
import { option } from '@typebot.io/forge'
|
import { option } from '@typebot.io/forge'
|
||||||
import { defaultOpenAIOptions } from './constants'
|
|
||||||
|
|
||||||
export const baseOptions = option
|
export const baseOptions = option
|
||||||
.object({
|
.object({
|
||||||
baseUrl: option.string.layout({
|
baseUrl: option.string.layout({
|
||||||
accordion: 'Customize provider',
|
accordion: 'Customize provider',
|
||||||
label: 'Base URL',
|
label: 'Base URL',
|
||||||
defaultValue: defaultOpenAIOptions.baseUrl,
|
|
||||||
}),
|
}),
|
||||||
apiVersion: option.string.layout({
|
apiVersion: option.string.layout({
|
||||||
accordion: 'Customize provider',
|
accordion: 'Customize provider',
|
||||||
|
@ -16,8 +16,7 @@ export const modelsWithImageUrlSupport = [
|
|||||||
export const excludedModelsFromImageUrlSupport = ['gpt-4-turbo-preview']
|
export const excludedModelsFromImageUrlSupport = ['gpt-4-turbo-preview']
|
||||||
|
|
||||||
export const defaultOpenAIOptions = {
|
export const defaultOpenAIOptions = {
|
||||||
baseUrl: 'https://api.openai.com/v1',
|
model: 'gpt-4o-mini',
|
||||||
model: 'gpt-3.5-turbo',
|
|
||||||
voiceModel: 'tts-1',
|
voiceModel: 'tts-1',
|
||||||
temperature: 1,
|
temperature: 1,
|
||||||
} as const
|
} as const
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import OpenAI, { ClientOptions } from 'openai'
|
import OpenAI, { ClientOptions } from 'openai'
|
||||||
import { defaultOpenAIOptions } from '../constants'
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
apiKey?: string
|
apiKey?: string
|
||||||
@ -9,14 +8,14 @@ type Props = {
|
|||||||
|
|
||||||
export const fetchGPTModels = async ({
|
export const fetchGPTModels = async ({
|
||||||
apiKey,
|
apiKey,
|
||||||
baseUrl = defaultOpenAIOptions.baseUrl,
|
baseUrl,
|
||||||
apiVersion,
|
apiVersion,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
if (!apiKey) return []
|
if (!apiKey) return []
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
apiKey: apiKey,
|
apiKey: apiKey,
|
||||||
baseURL: baseUrl ?? defaultOpenAIOptions.baseUrl,
|
baseURL: baseUrl,
|
||||||
defaultHeaders: {
|
defaultHeaders: {
|
||||||
'api-key': apiKey,
|
'api-key': apiKey,
|
||||||
},
|
},
|
||||||
|
@ -8,7 +8,7 @@ import { parseTools } from '@typebot.io/ai/parseTools'
|
|||||||
import { parseChatCompletionMessages } from '@typebot.io/ai/parseChatCompletionMessages'
|
import { parseChatCompletionMessages } from '@typebot.io/ai/parseChatCompletionMessages'
|
||||||
|
|
||||||
type OpenAIConfig = {
|
type OpenAIConfig = {
|
||||||
baseUrl: string
|
baseUrl?: string
|
||||||
defaultModel?: string
|
defaultModel?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,11 +37,6 @@ export const runOpenAIChatCompletion = async ({
|
|||||||
|
|
||||||
const model = createOpenAI({
|
const model = createOpenAI({
|
||||||
baseURL: openAIConfig.baseUrl ?? options.baseUrl,
|
baseURL: openAIConfig.baseUrl ?? options.baseUrl,
|
||||||
headers: options.baseUrl
|
|
||||||
? {
|
|
||||||
'api-key': apiKey,
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
apiKey,
|
apiKey,
|
||||||
compatibility,
|
compatibility,
|
||||||
})(modelName)
|
})(modelName)
|
||||||
|
@ -13,7 +13,7 @@ type Props = {
|
|||||||
credentials: { apiKey?: string }
|
credentials: { apiKey?: string }
|
||||||
options: ChatCompletionOptions
|
options: ChatCompletionOptions
|
||||||
variables: AsyncVariableStore
|
variables: AsyncVariableStore
|
||||||
config: { baseUrl: string; defaultModel?: string }
|
config: { baseUrl?: string; defaultModel?: string }
|
||||||
compatibility?: 'strict' | 'compatible'
|
compatibility?: 'strict' | 'compatible'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,11 +34,6 @@ export const runOpenAIChatCompletionStream = async ({
|
|||||||
|
|
||||||
const model = createOpenAI({
|
const model = createOpenAI({
|
||||||
baseURL: openAIConfig.baseUrl ?? options.baseUrl,
|
baseURL: openAIConfig.baseUrl ?? options.baseUrl,
|
||||||
headers: options.baseUrl
|
|
||||||
? {
|
|
||||||
'api-key': apiKey,
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
apiKey,
|
apiKey,
|
||||||
compatibility,
|
compatibility,
|
||||||
})(modelName)
|
})(modelName)
|
||||||
|
Reference in New Issue
Block a user