2024-04-20 04:02:19 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2024-04-20 05:48:52 +00:00
|
|
|
import toml from '@iarna/toml';
|
2024-04-20 04:02:19 +00:00
|
|
|
|
|
|
|
const configFileName = 'config.toml';
|
|
|
|
|
|
|
|
interface Config {
|
|
|
|
GENERAL: {
|
|
|
|
PORT: number;
|
|
|
|
SIMILARITY_MEASURE: string;
|
2024-04-20 05:48:52 +00:00
|
|
|
CHAT_MODEL_PROVIDER: string;
|
|
|
|
CHAT_MODEL: string;
|
2024-04-20 04:02:19 +00:00
|
|
|
};
|
|
|
|
API_KEYS: {
|
|
|
|
OPENAI: string;
|
|
|
|
};
|
|
|
|
API_ENDPOINTS: {
|
|
|
|
SEARXNG: string;
|
2024-04-20 05:48:52 +00:00
|
|
|
OLLAMA: string;
|
2024-04-20 04:02:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const loadConfig = () =>
|
|
|
|
toml.parse(
|
2024-04-20 05:48:52 +00:00
|
|
|
fs.readFileSync(path.join(__dirname, `../${configFileName}`), 'utf-8'),
|
2024-04-20 04:02:19 +00:00
|
|
|
) as any as Config;
|
|
|
|
|
|
|
|
export const getPort = () => loadConfig().GENERAL.PORT;
|
|
|
|
|
|
|
|
export const getSimilarityMeasure = () =>
|
|
|
|
loadConfig().GENERAL.SIMILARITY_MEASURE;
|
|
|
|
|
2024-04-20 05:48:52 +00:00
|
|
|
export const getChatModelProvider = () =>
|
|
|
|
loadConfig().GENERAL.CHAT_MODEL_PROVIDER;
|
|
|
|
|
|
|
|
export const getChatModel = () => loadConfig().GENERAL.CHAT_MODEL;
|
|
|
|
|
2024-04-20 04:02:19 +00:00
|
|
|
export const getOpenaiApiKey = () => loadConfig().API_KEYS.OPENAI;
|
|
|
|
|
|
|
|
export const getSearxngApiEndpoint = () => loadConfig().API_ENDPOINTS.SEARXNG;
|
2024-04-20 05:48:52 +00:00
|
|
|
|
|
|
|
export const getOllamaApiEndpoint = () => loadConfig().API_ENDPOINTS.OLLAMA;
|