Update config.ts

resolve conflict
This commit is contained in:
haddadrm
2025-02-15 15:24:24 +04:00
committed by GitHub
parent 0c908618c9
commit b38413e92d

View File

@@ -10,15 +10,32 @@ interface Config {
SIMILARITY_MEASURE: string; SIMILARITY_MEASURE: string;
KEEP_ALIVE: string; KEEP_ALIVE: string;
}; };
API_KEYS: { MODELS: {
OPENAI: string; OPENAI: {
GROQ: string; API_KEY: string;
ANTHROPIC: string; };
GEMINI: string; GROQ: {
API_KEY: string;
};
ANTHROPIC: {
API_KEY: string;
};
GEMINI: {
API_KEY: string;
};
OLLAMA: {
API_URL: string;
};
LMSTUDIO: {
API_URL: string;
};
CUSTOM_OPENAI: {
API_URL: string;
API_KEY: string;
MODEL_NAME: string;
};
}; };
API_ENDPOINTS: { API_ENDPOINTS: {
OLLAMA: string;
LMSTUDIO: string;
SEARXNG: string; SEARXNG: string;
}; };
} }
@@ -39,65 +56,63 @@ export const getSimilarityMeasure = () =>
export const getKeepAlive = () => loadConfig().GENERAL.KEEP_ALIVE; export const getKeepAlive = () => loadConfig().GENERAL.KEEP_ALIVE;
export const getOpenaiApiKey = () => loadConfig().API_KEYS.OPENAI; export const getOpenaiApiKey = () => loadConfig().MODELS.OPENAI.API_KEY;
export const getGroqApiKey = () => loadConfig().API_KEYS.GROQ; export const getGroqApiKey = () => loadConfig().MODELS.GROQ.API_KEY;
export const getAnthropicApiKey = () => loadConfig().API_KEYS.ANTHROPIC; export const getAnthropicApiKey = () => loadConfig().MODELS.ANTHROPIC.API_KEY;
export const getGeminiApiKey = () => loadConfig().API_KEYS.GEMINI; export const getGeminiApiKey = () => loadConfig().MODELS.GEMINI.API_KEY;
export const getSearxngApiEndpoint = () => export const getSearxngApiEndpoint = () =>
process.env.SEARXNG_API_URL || loadConfig().API_ENDPOINTS.SEARXNG; process.env.SEARXNG_API_URL || loadConfig().API_ENDPOINTS.SEARXNG;
export const getOllamaApiEndpoint = () => loadConfig().API_ENDPOINTS.OLLAMA; export const getOllamaApiEndpoint = () => loadConfig().MODELS.OLLAMA.API_URL;
export const getLMStudioApiEndpoint = () => loadConfig().API_ENDPOINTS.LMSTUDIO; export const getLMStudioApiEndpoint = () => loadConfig().MODELS.LMSTUDIO.API_URL;
export const updateConfig = (config: RecursivePartial<Config>) => { export const getCustomOpenaiApiKey = () =>
const currentConfig = loadConfig(); loadConfig().MODELS.CUSTOM_OPENAI.API_KEY;
for (const key in currentConfig) { export const getCustomOpenaiApiUrl = () =>
if (!config[key]) config[key] = {}; loadConfig().MODELS.CUSTOM_OPENAI.API_URL;
if (typeof currentConfig[key] === 'object' && currentConfig[key] !== null) { export const getCustomOpenaiModelName = () =>
for (const nestedKey in currentConfig[key]) { loadConfig().MODELS.CUSTOM_OPENAI.MODEL_NAME;
if (
!config[key][nestedKey] && const mergeConfigs = (current: any, update: any): any => {
currentConfig[key][nestedKey] && if (typeof current !== 'object' || current === null) {
config[key][nestedKey] !== '' return update;
) { }
config[key][nestedKey] = currentConfig[key][nestedKey];
} const result = { ...current };
for (const key in update) {
if (Object.prototype.hasOwnProperty.call(update, key)) {
const updateValue = update[key];
if (
typeof updateValue === 'object' &&
updateValue !== null &&
typeof result[key] === 'object' &&
result[key] !== null
) {
result[key] = mergeConfigs(result[key], updateValue);
} else if (updateValue !== undefined) {
result[key] = updateValue;
} }
} else if (currentConfig[key] && config[key] !== '') {
config[key] = currentConfig[key];
} }
} }
/* return result;
};
export const updateConfig = (config: RecursivePartial<Config>) => { export const updateConfig = (config: RecursivePartial<Config>) => {
const currentConfig = loadConfig(); const currentConfig = loadConfig();
const mergedConfig = mergeConfigs(currentConfig, config);
// Merge existing config with new values
const mergedConfig: RecursivePartial<Config> = {
GENERAL: {
...currentConfig.GENERAL,
...config.GENERAL,
},
API_KEYS: {
...currentConfig.API_KEYS,
...config.API_KEYS,
},
API_ENDPOINTS: {
...currentConfig.API_ENDPOINTS,
...config.API_ENDPOINTS,
},
};
*/
fs.writeFileSync( fs.writeFileSync(
path.join(__dirname, `../${configFileName}`), path.join(__dirname, `../${configFileName}`),
toml.stringify(config), toml.stringify(mergedConfig),
); );
}; };