Files
droid2api/config.js
1e0n 43803ca9da Add common endpoint support and system prompt injection, v1.1.0
- Add common endpoint type for GLM-4.6 model
- Implement automatic system prompt injection for all requests
- Simplify README documentation for better user focus
- Update version to 1.1.0
- Add *.txt to .gitignore

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2025-10-07 21:06:28 +08:00

52 lines
1.1 KiB
JavaScript

import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
let config = null;
export function loadConfig() {
try {
const configPath = path.join(__dirname, 'config.json');
const configData = fs.readFileSync(configPath, 'utf-8');
config = JSON.parse(configData);
return config;
} catch (error) {
throw new Error(`Failed to load config.json: ${error.message}`);
}
}
export function getConfig() {
if (!config) {
loadConfig();
}
return config;
}
export function getModelById(modelId) {
const cfg = getConfig();
return cfg.models.find(m => m.id === modelId);
}
export function getEndpointByType(type) {
const cfg = getConfig();
return cfg.endpoint.find(e => e.name === type);
}
export function isDevMode() {
const cfg = getConfig();
return cfg.dev_mode === true;
}
export function getPort() {
const cfg = getConfig();
return cfg.port || 3000;
}
export function getSystemPrompt() {
const cfg = getConfig();
return cfg.system_prompt || '';
}