mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-06-19 16:28:42 +00:00
Compare commits
3 Commits
v1.10.1
...
d892b9c0d4
Author | SHA1 | Date | |
---|---|---|---|
d892b9c0d4 | |||
a4c0fd7ea4 | |||
8e413796d6 |
@ -16,6 +16,8 @@ services:
|
|||||||
dockerfile: app.dockerfile
|
dockerfile: app.dockerfile
|
||||||
environment:
|
environment:
|
||||||
- SEARXNG_API_URL=http://searxng:8080
|
- SEARXNG_API_URL=http://searxng:8080
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
ports:
|
ports:
|
||||||
- 3000:3000
|
- 3000:3000
|
||||||
networks:
|
networks:
|
||||||
|
@ -40,37 +40,70 @@ type RecursivePartial<T> = {
|
|||||||
[P in keyof T]?: RecursivePartial<T[P]>;
|
[P in keyof T]?: RecursivePartial<T[P]>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadConfig = () =>
|
const loadConfig = () => {
|
||||||
toml.parse(
|
const configPath = path.join(process.cwd(), configFileName);
|
||||||
fs.readFileSync(path.join(process.cwd(), `${configFileName}`), 'utf-8'),
|
if (!fs.existsSync(configPath) || fs.lstatSync(configPath).isDirectory()) {
|
||||||
) as any as Config;
|
return {} as Config;
|
||||||
|
}
|
||||||
|
return toml.parse(fs.readFileSync(configPath, 'utf-8')) as any as Config;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getEnvVar = (key: string): string | undefined => {
|
||||||
|
return process.env[key];
|
||||||
|
};
|
||||||
|
|
||||||
|
const getConfigValue = (path: string[], defaultValue: string): string => {
|
||||||
|
// Convert path to environment variable name (e.g., ['MODELS', 'GROQ', 'API_KEY'] -> 'GROQ_API_KEY')
|
||||||
|
const envKey = path.slice(1).join('_').toUpperCase();
|
||||||
|
const envValue = getEnvVar(envKey);
|
||||||
|
|
||||||
|
if (envValue !== undefined) {
|
||||||
|
return envValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to config.toml
|
||||||
|
let value: any = loadConfig();
|
||||||
|
for (const key of path) {
|
||||||
|
value = value[key];
|
||||||
|
if (value === undefined) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
export const getSimilarityMeasure = () =>
|
export const getSimilarityMeasure = () =>
|
||||||
loadConfig().GENERAL.SIMILARITY_MEASURE;
|
getConfigValue(['GENERAL', 'SIMILARITY_MEASURE'], 'cosine');
|
||||||
|
|
||||||
export const getKeepAlive = () => loadConfig().GENERAL.KEEP_ALIVE;
|
export const getKeepAlive = () =>
|
||||||
|
getConfigValue(['GENERAL', 'KEEP_ALIVE'], '30s');
|
||||||
|
|
||||||
export const getOpenaiApiKey = () => loadConfig().MODELS.OPENAI.API_KEY;
|
export const getOpenaiApiKey = () =>
|
||||||
|
getConfigValue(['MODELS', 'OPENAI', 'API_KEY'], '');
|
||||||
|
|
||||||
export const getGroqApiKey = () => loadConfig().MODELS.GROQ.API_KEY;
|
export const getGroqApiKey = () =>
|
||||||
|
getConfigValue(['MODELS', 'GROQ', 'API_KEY'], '');
|
||||||
|
|
||||||
export const getAnthropicApiKey = () => loadConfig().MODELS.ANTHROPIC.API_KEY;
|
export const getAnthropicApiKey = () =>
|
||||||
|
getConfigValue(['MODELS', 'ANTHROPIC', 'API_KEY'], '');
|
||||||
|
|
||||||
export const getGeminiApiKey = () => loadConfig().MODELS.GEMINI.API_KEY;
|
export const getGeminiApiKey = () =>
|
||||||
|
getConfigValue(['MODELS', 'GEMINI', 'API_KEY'], '');
|
||||||
|
|
||||||
export const getSearxngApiEndpoint = () =>
|
export const getSearxngApiEndpoint = () =>
|
||||||
process.env.SEARXNG_API_URL || loadConfig().API_ENDPOINTS.SEARXNG;
|
process.env.SEARXNG_API_URL || getConfigValue(['API_ENDPOINTS', 'SEARXNG'], '');
|
||||||
|
|
||||||
export const getOllamaApiEndpoint = () => loadConfig().MODELS.OLLAMA.API_URL;
|
export const getOllamaApiEndpoint = () =>
|
||||||
|
getConfigValue(['MODELS', 'OLLAMA', 'API_URL'], 'http://localhost:11434');
|
||||||
|
|
||||||
export const getCustomOpenaiApiKey = () =>
|
export const getCustomOpenaiApiKey = () =>
|
||||||
loadConfig().MODELS.CUSTOM_OPENAI.API_KEY;
|
getConfigValue(['MODELS', 'CUSTOM_OPENAI', 'API_KEY'], '');
|
||||||
|
|
||||||
export const getCustomOpenaiApiUrl = () =>
|
export const getCustomOpenaiApiUrl = () =>
|
||||||
loadConfig().MODELS.CUSTOM_OPENAI.API_URL;
|
getConfigValue(['MODELS', 'CUSTOM_OPENAI', 'API_URL'], '');
|
||||||
|
|
||||||
export const getCustomOpenaiModelName = () =>
|
export const getCustomOpenaiModelName = () =>
|
||||||
loadConfig().MODELS.CUSTOM_OPENAI.MODEL_NAME;
|
getConfigValue(['MODELS', 'CUSTOM_OPENAI', 'MODEL_NAME'], '');
|
||||||
|
|
||||||
const mergeConfigs = (current: any, update: any): any => {
|
const mergeConfigs = (current: any, update: any): any => {
|
||||||
if (update === null || update === undefined) {
|
if (update === null || update === undefined) {
|
||||||
|
Reference in New Issue
Block a user