add support for openai baseUrl

This commit is contained in:
eric8810 2024-05-07 18:56:55 +08:00
parent 79f6a52b5b
commit 9dbfc69f11
3 changed files with 21 additions and 0 deletions

View file

@ -14,6 +14,7 @@ interface Config {
GROQ: string;
};
API_ENDPOINTS: {
OPENAI_BASE_URL: string;
SEARXNG: string;
OLLAMA: string;
};
@ -41,6 +42,9 @@ export const getSearxngApiEndpoint = () => loadConfig().API_ENDPOINTS.SEARXNG;
export const getOllamaApiEndpoint = () => loadConfig().API_ENDPOINTS.OLLAMA;
export const getOpenaiApiEndpoint = () =>
loadConfig().API_ENDPOINTS.OPENAI_BASE_URL;
export const updateConfig = (config: RecursivePartial<Config>) => {
const currentConfig = loadConfig();

View file

@ -4,6 +4,7 @@ import { OllamaEmbeddings } from '@langchain/community/embeddings/ollama';
import {
getGroqApiKey,
getOllamaApiEndpoint,
getOpenaiApiEndpoint,
getOpenaiApiKey,
} from '../config';
import logger from '../utils/logger';
@ -12,6 +13,7 @@ export const getAvailableProviders = async () => {
const openAIApiKey = getOpenaiApiKey();
const groqApiKey = getGroqApiKey();
const ollamaEndpoint = getOllamaApiEndpoint();
const openaiEndpoint = getOpenaiApiEndpoint();
const models = {};
@ -20,21 +22,33 @@ export const getAvailableProviders = async () => {
models['openai'] = {
'GPT-3.5 turbo': new ChatOpenAI({
openAIApiKey,
configuration: {
baseURL: openaiEndpoint,
},
modelName: 'gpt-3.5-turbo',
temperature: 0.7,
}),
'GPT-4': new ChatOpenAI({
openAIApiKey,
configuration: {
baseURL: openaiEndpoint,
},
modelName: 'gpt-4',
temperature: 0.7,
}),
'GPT-4 turbo': new ChatOpenAI({
openAIApiKey,
configuration: {
baseURL: openaiEndpoint,
},
modelName: 'gpt-4-turbo',
temperature: 0.7,
}),
embeddings: new OpenAIEmbeddings({
openAIApiKey,
configuration: {
baseURL: openaiEndpoint,
},
modelName: 'text-embedding-3-large',
}),
};

View file

@ -4,6 +4,7 @@ import {
getGroqApiKey,
getOllamaApiEndpoint,
getOpenaiApiKey,
getOpenaiApiEndpoint,
updateConfig,
} from '../config';
@ -27,6 +28,7 @@ router.get('/', async (_, res) => {
config['openaiApiKey'] = getOpenaiApiKey();
config['ollamaApiUrl'] = getOllamaApiEndpoint();
config['groqApiKey'] = getGroqApiKey();
config['openaiApiUrl'] = getOpenaiApiEndpoint();
res.status(200).json(config);
});
@ -41,6 +43,7 @@ router.post('/', async (req, res) => {
},
API_ENDPOINTS: {
OLLAMA: config.ollamaApiUrl,
OPENAI: config.openaiApiUrl,
},
};