feat(models): 配置新增 extra_params/thinking_params — 启停时按模型合并到上游请求体
This commit is contained in:
@@ -16,6 +16,11 @@ platforms:
|
||||
display_name: "AMD DeepSeek 1" # 显示名,缺省同 id
|
||||
# vision: true # 选填,默认 false;支持时 read_file 读图会压缩回传(长边≤2000px JPEG),会话上下文会告知 AI
|
||||
# enable: false # 选填,默认 true;禁用后不进模型池,不参与分配/绑定(重启生效)
|
||||
# extra_params: # 选填:每次发往上游都会合并进 body 顶层的对象;同 key 覆盖默认(model/messages/stream/temperature/tools)
|
||||
# top_p: 0.9
|
||||
# response_format: { type: "json_object" }
|
||||
# thinking_params: # 选填:仅「深度思考」开启时合并进 body(优先级高于 extra_params)
|
||||
# thinking: { type: "enabled", budget_tokens: 4096 }
|
||||
- id: ds2
|
||||
display_name: "AMD DeepSeek 2"
|
||||
- api_key: "sk-..." # 同平台的第二个 Key
|
||||
|
||||
@@ -99,6 +99,10 @@ function normalizePlatforms(rawPlatforms) {
|
||||
display_name: m.display_name ? String(m.display_name) : String(m.id),
|
||||
vision: m.vision === true, // 支持时 read_file 读图会回传图片,会话上下文会告知 AI
|
||||
enable: m.enable !== false, // 选填,默认启用;禁用后不进模型池,不参与分配/绑定(重启生效)
|
||||
// 选填:模型特有的请求体参数对象。发往上游时整体合并进 body 顶层。
|
||||
extra_params: (m.extra_params && typeof m.extra_params === 'object' && !Array.isArray(m.extra_params)) ? m.extra_params : {},
|
||||
// 选填:前端启用「深度思考」时合并进 body。可覆盖 extra_params 的同名键。
|
||||
thinking_params: (m.thinking_params && typeof m.thinking_params === 'object' && !Array.isArray(m.thinking_params)) ? m.thinking_params : {},
|
||||
});
|
||||
}
|
||||
keys.push({ api_key: String(k.api_key || ''), concurrency, models });
|
||||
@@ -131,6 +135,7 @@ function parseAndValidate(rawText, configPath) {
|
||||
// mid = 发给上游的原始模型名(请求体 body.model 用它)。
|
||||
id: p.name + '/' + m.id, mid: m.id,
|
||||
display_name: m.display_name, vision: m.vision, enable: m.enable,
|
||||
extra_params: m.extra_params, thinking_params: m.thinking_params,
|
||||
url: p.url, api_key: k.api_key, platform: p.name, type: p.type, concurrency: k.concurrency,
|
||||
platform_index: pi, key_index: ki, model_index: mi,
|
||||
});
|
||||
|
||||
@@ -562,6 +562,8 @@ async function streamAssistant(sessionId, run, session, messages, tools) {
|
||||
signal: run.abortController.signal,
|
||||
shouldCancel: () => run.cancelled,
|
||||
onText: delta => bus.emit(sessionId, 'assistant_delta', { text: delta }),
|
||||
// 本轮是否启用深度思考;由 postUserMessage 从消息 POST 参数写进 run
|
||||
deepThink: !!run.deepThink,
|
||||
});
|
||||
} finally {
|
||||
run.abortController = null;
|
||||
@@ -705,6 +707,8 @@ function createSession(title, preferModelId) {
|
||||
}
|
||||
|
||||
// 用户消息(或“开始执行”的模板消息)入口。
|
||||
// opts.deepThink: true 时启用深度思考;参数会记在会话 run 上,
|
||||
// 正在跑的回合下一轮迭代会取到最新值。新建会话需在 runLoop 之前先预建 run 以携带该值。
|
||||
function postUserMessage(sessionId, content, opts) {
|
||||
const session = getSession(sessionId);
|
||||
if (!session) throw Object.assign(new Error('会话不存在'), { status_code: 404 });
|
||||
@@ -712,8 +716,10 @@ function postUserMessage(sessionId, content, opts) {
|
||||
if (!session.title) {
|
||||
touch(sessionId, { title: content.slice(0, 24) });
|
||||
}
|
||||
const run = runs.get(sessionId);
|
||||
if (session.status === 'active' && run && run.looping) {
|
||||
// 预建/更新 run 记录,记下本轮的 deepThink(被 runLoop / callModel 读取)
|
||||
const run = getRun(sessionId, true);
|
||||
run.deepThink = !!(opts && opts.deepThink);
|
||||
if (session.status === 'active' && run.looping) {
|
||||
// 正在跑:下一轮迭代会从 DB 重新加载历史,自动带上这条消息
|
||||
return { message_id: messageId, delivered: 'live' };
|
||||
}
|
||||
@@ -724,7 +730,7 @@ function postUserMessage(sessionId, content, opts) {
|
||||
runLoop(sessionId);
|
||||
return { message_id: messageId, delivered: 'live' };
|
||||
}
|
||||
if (session.status === 'active' && (!run || !run.looping)) {
|
||||
if (session.status === 'active' && !run.looping) {
|
||||
runLoop(sessionId);
|
||||
return { message_id: messageId, delivered: 'live' };
|
||||
}
|
||||
|
||||
@@ -99,8 +99,23 @@ async function forEachSSEData(response, onEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
// 深度合并 src 到 dst(就地改 dst):同名键两边都是普通对象则递归;其余 src 覆盖 dst。
|
||||
// 用于将模型的 extra_params / thinking_params 合入上游请求体。
|
||||
function deepMergeInto(dst, src) {
|
||||
for (const k of Object.keys(src || {})) {
|
||||
const sv = src[k];
|
||||
if (sv && typeof sv === 'object' && !Array.isArray(sv) && dst[k] && typeof dst[k] === 'object' && !Array.isArray(dst[k])) {
|
||||
deepMergeInto(dst[k], sv);
|
||||
} else {
|
||||
dst[k] = sv;
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
// 调模型一次。onText(textDelta) 回调流式文本。
|
||||
// 返回 { content, tool_calls: [{id,name,arguments(string)}], finish_reason, usage, aborted }
|
||||
// options.deepThink: true 时将 modelCfg.thinking_params 合并进 body。
|
||||
async function callModel(cfg, modelId, messages, tools, options) {
|
||||
const opts = options || {};
|
||||
const controller = new AbortController();
|
||||
@@ -120,6 +135,13 @@ async function callModel(cfg, modelId, messages, tools, options) {
|
||||
temperature: cfg.agent.temperature,
|
||||
};
|
||||
if (tools && tools.length) body.tools = tools;
|
||||
// 模型特有请求参数:与内置字段同名时额外优先(同时思考参数可覆盖)
|
||||
if (modelCfg.extra_params && Object.keys(modelCfg.extra_params).length) {
|
||||
deepMergeInto(body, modelCfg.extra_params);
|
||||
}
|
||||
if (opts.deepThink && modelCfg.thinking_params && Object.keys(modelCfg.thinking_params).length) {
|
||||
deepMergeInto(body, modelCfg.thinking_params);
|
||||
}
|
||||
|
||||
const headers = { 'Content-Type': 'application/json' };
|
||||
if (modelCfg.api_key) headers.Authorization = 'Bearer ' + modelCfg.api_key;
|
||||
|
||||
@@ -269,7 +269,6 @@
|
||||
*
|
||||
* 无后端支撑、仅前端占位的概念(先不实现):
|
||||
* · 「文秘助理 / 识图专家」模式 —— 后端无 mode 字段,当前仅影响提示文案
|
||||
* · 「深度思考」开关 —— 后端无 reasoning/deep-think 参数,当前仅本地视觉状态
|
||||
* · 「思考过程」折叠块(已思考 N 秒) —— 后端不产出 reasoning,已移除 mock
|
||||
* · 按条删除消息 —— 后端无消息级删除接口;消息下方的删除会话按钮已整体移除(改用状态栏「清空」)
|
||||
* 鉴权:任意请求 401 时跳转 /login(与 core.js 的 req 一致)。
|
||||
@@ -937,7 +936,7 @@
|
||||
const id = await ensureSession();
|
||||
let atts = [];
|
||||
if (pending.length) atts = await uploadFiles(id, pending);
|
||||
const body = { content };
|
||||
const body = { content, deepThink: !!state.deepThink };
|
||||
if (atts.length) body.attachments = atts;
|
||||
await req('POST', '/api/sessions/' + id + '/messages', body);
|
||||
|
||||
@@ -1180,11 +1179,11 @@
|
||||
});
|
||||
$('send-btn').addEventListener('click', () => send()); // 发送按钮与 Enter 行为一致
|
||||
|
||||
// 深度思考开关(仅本地视觉状态,后端无 reasoning 参数)
|
||||
// 深度思考开关:每次发消息随 body 传给后端,后端会合并该模型的 thinking_params
|
||||
$('deep-think-btn').addEventListener('click', () => {
|
||||
state.deepThink = !state.deepThink;
|
||||
$('deep-think-btn').classList.toggle('on', state.deepThink);
|
||||
toast(state.deepThink ? '深度思考已开启(暂不影响后端)' : '深度思考已关闭');
|
||||
toast(state.deepThink ? '深度思考已开启' : '深度思考已关闭');
|
||||
});
|
||||
|
||||
// ---------- 任务文件面板(底部浮层:点输入行右侧发送旁的附件按钮展开,遮罩盖住输入区) ----------
|
||||
|
||||
@@ -41,7 +41,9 @@ router.post('/:id/messages', wrap((req, res) => {
|
||||
req.body && req.body.attachments
|
||||
);
|
||||
if (!content) return res.status(400).json({ error: 'content 不能为空' });
|
||||
const r = engine.postUserMessage(req.params.id, content);
|
||||
// deepThink:是否启用模型该「深度思考」参数(thinking_params 合并进上游请求体)
|
||||
const deepThink = !!(req.body && req.body.deepThink);
|
||||
const r = engine.postUserMessage(req.params.id, content, { deepThink });
|
||||
log.info('[msg] ' + (req.user || '-') + ' ' + req.params.id + ' 用户消息(' + (r && r.delivered || '?') + '):' +
|
||||
content.slice(0, 60).replace(/\s+/g, ' '));
|
||||
res.json(r);
|
||||
|
||||
Reference in New Issue
Block a user