models 配置改为每模型独立 url/api_key:移除全局 upstream_url/api_key,config.js 校验每模型必填 url(选填 api_key,去尾斜杠),llm.callModel 按 model_id 解析各自上游与鉴权头,server 启动日志逐模型打印 url;example/test 配置与 README/DEPLOY 同步(本地 config.yml 已改为同值独立结构,gitignore 不入库)
This commit is contained in:
+5
-2
@@ -66,6 +66,9 @@ async function callModel(cfg, modelId, messages, tools, options) {
|
||||
if (opts.signal.aborted) controller.abort();
|
||||
else opts.signal.addEventListener('abort', () => controller.abort());
|
||||
}
|
||||
const modelCfg = (cfg.models || []).find(m => m.id === modelId);
|
||||
if (!modelCfg || !modelCfg.url) throw new Error('模型未在配置中定义或缺少独立 url: ' + modelId);
|
||||
|
||||
const body = {
|
||||
model: modelId,
|
||||
messages,
|
||||
@@ -76,9 +79,9 @@ async function callModel(cfg, modelId, messages, tools, options) {
|
||||
if (tools && tools.length) body.tools = tools;
|
||||
|
||||
const headers = { 'Content-Type': 'application/json' };
|
||||
if (cfg.api_key) headers.Authorization = 'Bearer ' + cfg.api_key;
|
||||
if (modelCfg.api_key) headers.Authorization = 'Bearer ' + modelCfg.api_key;
|
||||
|
||||
const res = await fetch(cfg.upstream_url + '/chat/completions', {
|
||||
const res = await fetch(modelCfg.url + '/chat/completions', {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(body),
|
||||
|
||||
Reference in New Issue
Block a user