⚡️(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({
|
||||
...params,
|
||||
config: {
|
||||
baseUrl: defaultOpenAIOptions.baseUrl,
|
||||
baseUrl: params.credentials.baseUrl,
|
||||
defaultModel: defaultOpenAIOptions.model,
|
||||
},
|
||||
compatibility: 'strict',
|
||||
@ -68,7 +68,7 @@ export const createChatCompletion = createAction({
|
||||
runOpenAIChatCompletionStream({
|
||||
...params,
|
||||
config: {
|
||||
baseUrl: defaultOpenAIOptions.baseUrl,
|
||||
baseUrl: params.credentials.baseUrl,
|
||||
defaultModel: defaultOpenAIOptions.model,
|
||||
},
|
||||
compatibility: 'strict',
|
||||
|
@ -39,10 +39,10 @@ export const createSpeech = createAction({
|
||||
fetch: async ({ credentials, options }) => {
|
||||
if (!credentials?.apiKey) return []
|
||||
|
||||
const baseUrl = options?.baseUrl ?? defaultOpenAIOptions.baseUrl
|
||||
const baseUrl = options?.baseUrl
|
||||
const config = {
|
||||
apiKey: credentials.apiKey,
|
||||
baseURL: baseUrl ?? defaultOpenAIOptions.baseUrl,
|
||||
baseURL: baseUrl,
|
||||
defaultHeaders: {
|
||||
'api-key': credentials.apiKey,
|
||||
},
|
||||
@ -75,7 +75,7 @@ export const createSpeech = createAction({
|
||||
|
||||
const config = {
|
||||
apiKey,
|
||||
baseURL: options.baseUrl ?? defaultOpenAIOptions.baseUrl,
|
||||
baseURL: options.baseUrl,
|
||||
defaultHeaders: {
|
||||
'api-key': apiKey,
|
||||
},
|
||||
|
@ -29,7 +29,7 @@ export const createTranscription = createAction({
|
||||
|
||||
const config = {
|
||||
apiKey,
|
||||
baseURL: options.baseUrl ?? defaultOpenAIOptions.baseUrl,
|
||||
baseURL: options.baseUrl,
|
||||
defaultHeaders: {
|
||||
'api-key': apiKey,
|
||||
},
|
||||
|
@ -14,5 +14,11 @@ export const auth = createAuth({
|
||||
withVariableButton: false,
|
||||
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 { defaultOpenAIOptions } from './constants'
|
||||
|
||||
export const baseOptions = option
|
||||
.object({
|
||||
baseUrl: option.string.layout({
|
||||
accordion: 'Customize provider',
|
||||
label: 'Base URL',
|
||||
defaultValue: defaultOpenAIOptions.baseUrl,
|
||||
}),
|
||||
apiVersion: option.string.layout({
|
||||
accordion: 'Customize provider',
|
||||
|
@ -16,8 +16,7 @@ export const modelsWithImageUrlSupport = [
|
||||
export const excludedModelsFromImageUrlSupport = ['gpt-4-turbo-preview']
|
||||
|
||||
export const defaultOpenAIOptions = {
|
||||
baseUrl: 'https://api.openai.com/v1',
|
||||
model: 'gpt-3.5-turbo',
|
||||
model: 'gpt-4o-mini',
|
||||
voiceModel: 'tts-1',
|
||||
temperature: 1,
|
||||
} as const
|
||||
|
@ -1,5 +1,4 @@
|
||||
import OpenAI, { ClientOptions } from 'openai'
|
||||
import { defaultOpenAIOptions } from '../constants'
|
||||
|
||||
type Props = {
|
||||
apiKey?: string
|
||||
@ -9,14 +8,14 @@ type Props = {
|
||||
|
||||
export const fetchGPTModels = async ({
|
||||
apiKey,
|
||||
baseUrl = defaultOpenAIOptions.baseUrl,
|
||||
baseUrl,
|
||||
apiVersion,
|
||||
}: Props) => {
|
||||
if (!apiKey) return []
|
||||
|
||||
const config = {
|
||||
apiKey: apiKey,
|
||||
baseURL: baseUrl ?? defaultOpenAIOptions.baseUrl,
|
||||
baseURL: baseUrl,
|
||||
defaultHeaders: {
|
||||
'api-key': apiKey,
|
||||
},
|
||||
|
@ -8,7 +8,7 @@ import { parseTools } from '@typebot.io/ai/parseTools'
|
||||
import { parseChatCompletionMessages } from '@typebot.io/ai/parseChatCompletionMessages'
|
||||
|
||||
type OpenAIConfig = {
|
||||
baseUrl: string
|
||||
baseUrl?: string
|
||||
defaultModel?: string
|
||||
}
|
||||
|
||||
@ -37,11 +37,6 @@ export const runOpenAIChatCompletion = async ({
|
||||
|
||||
const model = createOpenAI({
|
||||
baseURL: openAIConfig.baseUrl ?? options.baseUrl,
|
||||
headers: options.baseUrl
|
||||
? {
|
||||
'api-key': apiKey,
|
||||
}
|
||||
: undefined,
|
||||
apiKey,
|
||||
compatibility,
|
||||
})(modelName)
|
||||
|
@ -13,7 +13,7 @@ type Props = {
|
||||
credentials: { apiKey?: string }
|
||||
options: ChatCompletionOptions
|
||||
variables: AsyncVariableStore
|
||||
config: { baseUrl: string; defaultModel?: string }
|
||||
config: { baseUrl?: string; defaultModel?: string }
|
||||
compatibility?: 'strict' | 'compatible'
|
||||
}
|
||||
|
||||
@ -34,11 +34,6 @@ export const runOpenAIChatCompletionStream = async ({
|
||||
|
||||
const model = createOpenAI({
|
||||
baseURL: openAIConfig.baseUrl ?? options.baseUrl,
|
||||
headers: options.baseUrl
|
||||
? {
|
||||
'api-key': apiKey,
|
||||
}
|
||||
: undefined,
|
||||
apiKey,
|
||||
compatibility,
|
||||
})(modelName)
|
||||
|
Reference in New Issue
Block a user