增加多种配置文件格式支持
parent
ba06f46898
commit
b3fb6186e5
@ -1,3 +1,5 @@
|
||||
node_modules/
|
||||
/dist/
|
||||
/config.yaml
|
||||
/config.yaml
|
||||
/config.jsonc
|
||||
/config.json5
|
||||
@ -0,0 +1,19 @@
|
||||
{
|
||||
"$schema": "schemas/ServerConfig.json",
|
||||
"port": 6800,
|
||||
"db_type": "postgres",
|
||||
"db": {
|
||||
"host": "localhost",
|
||||
"port": 5432,
|
||||
"user": "memory_proxy",
|
||||
"password": "memory_proxy",
|
||||
"database": "memory_proxy"
|
||||
},
|
||||
"memory_max_messages": 1000,
|
||||
"proxies": {
|
||||
"deepseek": {
|
||||
"endpoint": "https://api.deepseek.com",
|
||||
"type": "openai"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
import '#app/cli/ExportSchemas';
|
||||
@ -1,3 +1,3 @@
|
||||
import App from '#app/App';
|
||||
|
||||
new App("./config.yaml");
|
||||
new App();
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,99 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"debug": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to enable debug mode."
|
||||
},
|
||||
"port": {
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
"maximum": 65535,
|
||||
"description": "The server port."
|
||||
},
|
||||
"memory_max_messages": {
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
"description": "The maximum number of messages to remember."
|
||||
},
|
||||
"db_type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"postgres"
|
||||
],
|
||||
"description": "The type of database, currently only supports Postgres."
|
||||
},
|
||||
"db": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"host": {
|
||||
"type": "string",
|
||||
"description": "The host of the Postgres database."
|
||||
},
|
||||
"port": {
|
||||
"type": "integer",
|
||||
"description": "The port of the Postgres database."
|
||||
},
|
||||
"user": {
|
||||
"type": "string",
|
||||
"description": "The username for the Postgres database."
|
||||
},
|
||||
"password": {
|
||||
"type": "string",
|
||||
"description": "The password for the Postgres database."
|
||||
},
|
||||
"database": {
|
||||
"type": "string",
|
||||
"description": "The name of the Postgres database."
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"description": "Configuration for the Postgres database."
|
||||
},
|
||||
"proxies": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"description": "The type of the LLM proxy, e.g., \"openai\", \"azure\", etc."
|
||||
},
|
||||
"endpoint": {
|
||||
"type": "string",
|
||||
"description": "The endpoint URL of the LLM proxy."
|
||||
},
|
||||
"http_proxy": {
|
||||
"type": "string",
|
||||
"description": "Optional HTTP proxy URL for the LLM proxy."
|
||||
},
|
||||
"socks_proxy": {
|
||||
"type": "string",
|
||||
"description": "Optional SOCKS proxy URL for the LLM proxy."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"endpoint"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"description": "A record of LLM proxy configurations."
|
||||
},
|
||||
"api_keys": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "A list of API keys for authentication."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"port",
|
||||
"memory_max_messages",
|
||||
"proxies",
|
||||
"api_keys"
|
||||
],
|
||||
"additionalProperties": true,
|
||||
"$schema": "http://json-schema.org/draft-07/schema#"
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
import { ServerConfigSchema } from "#app/schemas/ServerConfig.js";
|
||||
import { z } from "koa-swagger-decorator";
|
||||
import { zodToJsonSchema } from "@bpinternal/zod-to-json-schema";
|
||||
import fs from 'fs';
|
||||
|
||||
const schemaMap = {
|
||||
'ServerConfig': ServerConfigSchema,
|
||||
}
|
||||
|
||||
const outputDir = './schemas'; // 输出目录
|
||||
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
fs.mkdirSync(outputDir, { recursive: true });
|
||||
}
|
||||
|
||||
for (let [name, schema] of Object.entries(schemaMap)) {
|
||||
// 导出为 JSON 文件
|
||||
const outputFile = `${outputDir}/${name}.json`;
|
||||
console.log(`Exporting schema ${name} to ${outputFile}`);
|
||||
fs.writeFileSync(outputFile, JSON.stringify(zodToJsonSchema(schema), null, 2));
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
import { z } from 'koa-swagger-decorator';
|
||||
|
||||
export const LLMProxyConfigSchema = z.object({
|
||||
type: z.string().describe('The type of the LLM proxy, e.g., "openai", "azure", etc.'),
|
||||
endpoint: z.string().describe('The endpoint URL of the LLM proxy.'),
|
||||
http_proxy: z.string().optional().describe('Optional HTTP proxy URL for the LLM proxy.'),
|
||||
socks_proxy: z.string().optional().describe('Optional SOCKS proxy URL for the LLM proxy.'),
|
||||
});
|
||||
|
||||
export type LLMProxyConfig = z.infer<typeof LLMProxyConfigSchema>;
|
||||
|
||||
export const PostgresDatabaseConfigSchema = z.object({
|
||||
host: z.string().optional().describe('The host of the Postgres database.'),
|
||||
port: z.number().int().optional().describe('The port of the Postgres database.'),
|
||||
user: z.string().optional().describe('The username for the Postgres database.'),
|
||||
password: z.string().optional().describe('The password for the Postgres database.'),
|
||||
database: z.string().optional().describe('The name of the Postgres database.'),
|
||||
});
|
||||
|
||||
export type PostgresDatabaseConfig = z.infer<typeof PostgresDatabaseConfigSchema>;
|
||||
|
||||
export const ServerConfigSchema = z.object({
|
||||
debug: z.boolean().optional().describe('Whether to enable debug mode.'),
|
||||
port: z.number().int().min(1).max(65535).describe('The server port.'),
|
||||
memory_max_messages: z.number().int().min(1).describe('The maximum number of messages to remember.'),
|
||||
db_type: z.enum(['postgres']).optional().describe('The type of database, currently only supports Postgres.'),
|
||||
db: PostgresDatabaseConfigSchema.optional().describe('Configuration for the Postgres database.'),
|
||||
proxies: z.record(LLMProxyConfigSchema).describe('A record of LLM proxy configurations.'),
|
||||
api_keys: z.array(z.string()).describe('A list of API keys for authentication.'),
|
||||
}).passthrough();
|
||||
|
||||
export type ServerConfig = z.infer<typeof ServerConfigSchema>;
|
||||
@ -1,24 +0,0 @@
|
||||
export interface LLMProxyConfig {
|
||||
type: string;
|
||||
endpoint: string;
|
||||
http_proxy?: string;
|
||||
socks_proxy?: string;
|
||||
}
|
||||
|
||||
export interface PostgresDatabaseConfig {
|
||||
host?: string;
|
||||
port?: number;
|
||||
user?: string;
|
||||
password?: string;
|
||||
database?: string;
|
||||
}
|
||||
|
||||
export interface ServerConfig {
|
||||
debug?: boolean; // 是否开启调试模式
|
||||
port: number; // 服务器端口
|
||||
memory_max_messages: number; // 记忆中的最大消息数
|
||||
db_type?: "postgres"; // 数据库类型,目前只支持 Postgres
|
||||
db?: PostgresDatabaseConfig;
|
||||
proxies: Record<string, LLMProxyConfig>;
|
||||
api_keys: string[];
|
||||
}
|
||||
Loading…
Reference in New Issue