Add OPENAI_BASE_URL configuration option
This commit is contained in:
parent
408abd24ea
commit
57ee62f3af
5 changed files with 74 additions and 23 deletions
|
|
@ -4,6 +4,7 @@ SIMILARITY_MEASURE = "cosine" # "cosine" or "dot"
|
||||||
|
|
||||||
[API_KEYS]
|
[API_KEYS]
|
||||||
OPENAI = "" # OpenAI API key - sk-1234567890abcdef1234567890abcdef
|
OPENAI = "" # OpenAI API key - sk-1234567890abcdef1234567890abcdef
|
||||||
|
OPENAI_BASE_URL = "https://api.openai.com/v1" # OpenAI API base URL
|
||||||
GROQ = "" # Groq API key - gsk_1234567890abcdef1234567890abcdef
|
GROQ = "" # Groq API key - gsk_1234567890abcdef1234567890abcdef
|
||||||
|
|
||||||
[API_ENDPOINTS]
|
[API_ENDPOINTS]
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ interface Config {
|
||||||
};
|
};
|
||||||
API_KEYS: {
|
API_KEYS: {
|
||||||
OPENAI: string;
|
OPENAI: string;
|
||||||
|
OPENAI_BASE_URL: string;
|
||||||
GROQ: string;
|
GROQ: string;
|
||||||
};
|
};
|
||||||
API_ENDPOINTS: {
|
API_ENDPOINTS: {
|
||||||
|
|
@ -35,6 +36,9 @@ export const getSimilarityMeasure = () =>
|
||||||
|
|
||||||
export const getOpenaiApiKey = () => loadConfig().API_KEYS.OPENAI;
|
export const getOpenaiApiKey = () => loadConfig().API_KEYS.OPENAI;
|
||||||
|
|
||||||
|
export const getOpenaiBaseUrl = () =>
|
||||||
|
loadConfig().API_KEYS.OPENAI_BASE_URL || 'https://api.openai.com/v1';
|
||||||
|
|
||||||
export const getGroqApiKey = () => loadConfig().API_KEYS.GROQ;
|
export const getGroqApiKey = () => loadConfig().API_KEYS.GROQ;
|
||||||
|
|
||||||
export const getSearxngApiEndpoint = () => loadConfig().API_ENDPOINTS.SEARXNG;
|
export const getSearxngApiEndpoint = () => loadConfig().API_ENDPOINTS.SEARXNG;
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,13 @@ import {
|
||||||
getGroqApiKey,
|
getGroqApiKey,
|
||||||
getOllamaApiEndpoint,
|
getOllamaApiEndpoint,
|
||||||
getOpenaiApiKey,
|
getOpenaiApiKey,
|
||||||
|
getOpenaiBaseUrl,
|
||||||
} from '../config';
|
} from '../config';
|
||||||
import logger from '../utils/logger';
|
import logger from '../utils/logger';
|
||||||
|
|
||||||
export const getAvailableProviders = async () => {
|
export const getAvailableProviders = async () => {
|
||||||
const openAIApiKey = getOpenaiApiKey();
|
const openAIApiKey = getOpenaiApiKey();
|
||||||
|
const openAIBaseUrl = getOpenaiBaseUrl();
|
||||||
const groqApiKey = getGroqApiKey();
|
const groqApiKey = getGroqApiKey();
|
||||||
const ollamaEndpoint = getOllamaApiEndpoint();
|
const ollamaEndpoint = getOllamaApiEndpoint();
|
||||||
|
|
||||||
|
|
@ -18,25 +20,45 @@ export const getAvailableProviders = async () => {
|
||||||
if (openAIApiKey) {
|
if (openAIApiKey) {
|
||||||
try {
|
try {
|
||||||
models['openai'] = {
|
models['openai'] = {
|
||||||
'GPT-3.5 turbo': new ChatOpenAI({
|
'GPT-3.5 turbo': new ChatOpenAI(
|
||||||
|
{
|
||||||
openAIApiKey,
|
openAIApiKey,
|
||||||
modelName: 'gpt-3.5-turbo',
|
modelName: 'gpt-3.5-turbo',
|
||||||
temperature: 0.7,
|
temperature: 0.7,
|
||||||
}),
|
},
|
||||||
'GPT-4': new ChatOpenAI({
|
{
|
||||||
|
baseURL: openAIBaseUrl,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
'GPT-4': new ChatOpenAI(
|
||||||
|
{
|
||||||
openAIApiKey,
|
openAIApiKey,
|
||||||
modelName: 'gpt-4',
|
modelName: 'gpt-4',
|
||||||
temperature: 0.7,
|
temperature: 0.7,
|
||||||
}),
|
},
|
||||||
'GPT-4 turbo': new ChatOpenAI({
|
{
|
||||||
|
baseURL: openAIBaseUrl,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
'GPT-4 turbo': new ChatOpenAI(
|
||||||
|
{
|
||||||
openAIApiKey,
|
openAIApiKey,
|
||||||
modelName: 'gpt-4-turbo',
|
modelName: 'gpt-4-turbo',
|
||||||
temperature: 0.7,
|
temperature: 0.7,
|
||||||
}),
|
},
|
||||||
embeddings: new OpenAIEmbeddings({
|
{
|
||||||
|
baseURL: openAIBaseUrl,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
embeddings: new OpenAIEmbeddings(
|
||||||
|
{
|
||||||
openAIApiKey,
|
openAIApiKey,
|
||||||
modelName: 'text-embedding-3-large',
|
modelName: 'text-embedding-3-large',
|
||||||
}),
|
},
|
||||||
|
{
|
||||||
|
baseURL: openAIBaseUrl,
|
||||||
|
},
|
||||||
|
),
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(`Error loading OpenAI models: ${err}`);
|
logger.error(`Error loading OpenAI models: ${err}`);
|
||||||
|
|
@ -86,10 +108,15 @@ export const getAvailableProviders = async () => {
|
||||||
baseURL: 'https://api.groq.com/openai/v1',
|
baseURL: 'https://api.groq.com/openai/v1',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
embeddings: new OpenAIEmbeddings({
|
embeddings: new OpenAIEmbeddings(
|
||||||
|
{
|
||||||
openAIApiKey: openAIApiKey,
|
openAIApiKey: openAIApiKey,
|
||||||
modelName: 'text-embedding-3-large',
|
modelName: 'text-embedding-3-large',
|
||||||
}),
|
},
|
||||||
|
{
|
||||||
|
baseURL: openAIBaseUrl,
|
||||||
|
},
|
||||||
|
),
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(`Error loading Groq models: ${err}`);
|
logger.error(`Error loading Groq models: ${err}`);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {
|
||||||
getGroqApiKey,
|
getGroqApiKey,
|
||||||
getOllamaApiEndpoint,
|
getOllamaApiEndpoint,
|
||||||
getOpenaiApiKey,
|
getOpenaiApiKey,
|
||||||
|
getOpenaiBaseUrl,
|
||||||
updateConfig,
|
updateConfig,
|
||||||
} from '../config';
|
} from '../config';
|
||||||
|
|
||||||
|
|
@ -25,6 +26,7 @@ router.get('/', async (_, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
config['openaiApiKey'] = getOpenaiApiKey();
|
config['openaiApiKey'] = getOpenaiApiKey();
|
||||||
|
config['openaiBaseUrl'] = getOpenaiBaseUrl();
|
||||||
config['ollamaApiUrl'] = getOllamaApiEndpoint();
|
config['ollamaApiUrl'] = getOllamaApiEndpoint();
|
||||||
config['groqApiKey'] = getGroqApiKey();
|
config['groqApiKey'] = getGroqApiKey();
|
||||||
|
|
||||||
|
|
@ -37,6 +39,7 @@ router.post('/', async (req, res) => {
|
||||||
const updatedConfig = {
|
const updatedConfig = {
|
||||||
API_KEYS: {
|
API_KEYS: {
|
||||||
OPENAI: config.openaiApiKey,
|
OPENAI: config.openaiApiKey,
|
||||||
|
OPENAI_BASE_URL: config.openaiBaseUrl,
|
||||||
GROQ: config.groqApiKey,
|
GROQ: config.groqApiKey,
|
||||||
},
|
},
|
||||||
API_ENDPOINTS: {
|
API_ENDPOINTS: {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ interface SettingsType {
|
||||||
[key: string]: string[];
|
[key: string]: string[];
|
||||||
};
|
};
|
||||||
openaiApiKey: string;
|
openaiApiKey: string;
|
||||||
|
openaiBaseUrl: string;
|
||||||
groqApiKey: string;
|
groqApiKey: string;
|
||||||
ollamaApiUrl: string;
|
ollamaApiUrl: string;
|
||||||
}
|
}
|
||||||
|
|
@ -183,6 +184,21 @@ const SettingsDialog = ({
|
||||||
className="bg-[#111111] px-3 py-2 flex items-center overflow-hidden border border-[#1C1C1C] text-white rounded-lg text-sm"
|
className="bg-[#111111] px-3 py-2 flex items-center overflow-hidden border border-[#1C1C1C] text-white rounded-lg text-sm"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex flex-col space-y-1">
|
||||||
|
<p className="text-white/70 text-sm">OpenAI Base URL</p>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="OpenAI Base URL"
|
||||||
|
defaultValue={config.openaiBaseUrl}
|
||||||
|
onChange={(e) =>
|
||||||
|
setConfig({
|
||||||
|
...config,
|
||||||
|
openaiBaseUrl: e.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
className="bg-[#111111] px-3 py-2 flex items-center overflow-hidden border border-[#1C1C1C] text-white rounded-lg text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div className="flex flex-col space-y-1">
|
<div className="flex flex-col space-y-1">
|
||||||
<p className="text-white/70 text-sm">Ollama API URL</p>
|
<p className="text-white/70 text-sm">Ollama API URL</p>
|
||||||
<input
|
<input
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue