perplexica/src/config.ts

33 lines
734 B
TypeScript
Raw Normal View History

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