From 5fe572c433772937bafa75f0d327284a2cda101e Mon Sep 17 00:00:00 2001 From: Silence_Lurker Date: Tue, 20 Jan 2026 10:20:28 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E5=8F=82=E6=95=B0=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E9=80=BB=E8=BE=91=EF=BC=8C=E5=B0=81=E8=A3=85=20Profil?= =?UTF-8?q?e=20=E5=8F=82=E6=95=B0=E6=8F=90=E5=8F=96=E8=87=B3=20=5FbuildPro?= =?UTF-8?q?filePayload=20=E6=96=B9=E6=B3=95=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E5=90=8E=E7=AB=AF=E6=AD=A3=E7=A1=AE=E5=BA=94=E7=94=A8=E9=A2=84?= =?UTF-8?q?=E8=AE=BE=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SL/bus/api/ModelCaller.js | 61 +++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/SL/bus/api/ModelCaller.js b/SL/bus/api/ModelCaller.js index 58ba823..65303f4 100644 --- a/SL/bus/api/ModelCaller.js +++ b/SL/bus/api/ModelCaller.js @@ -116,41 +116,17 @@ export default class ModelCaller { const url = '/api/backends/chat-completions/generate'; // [修复]: 手动合并 Profile 中的关键参数,否则后端不会自动应用预设配置 - // 我们需要模拟 ST 前端发送请求时的行为,把预设参数填进去 - const profilePayload = { - // 基础模型参数 - model: targetProfile.openai_model || targetProfile.model, - temperature: targetProfile.temperature, - frequency_penalty: targetProfile.frequency_penalty, - presence_penalty: targetProfile.presence_penalty, - top_p: targetProfile.top_p, - top_k: targetProfile.top_k, - min_p: targetProfile.min_p, - repetition_penalty: targetProfile.repetition_penalty, - - // 关键:OpenAI 源标记 - chat_completion_source: targetProfile.chat_completion_source || 'openai', - - // 代理设置 (如果预设里有) - reverse_proxy: targetProfile.reverse_proxy, - proxy_password: targetProfile.proxy_password, - - // 其他可能影响生成的参数 - custom_prompt_post_processing: targetProfile.custom_prompt_post_processing ?? 'strict', - }; + // 提取逻辑已封装至 _buildProfilePayload + const profilePayload = this._buildProfilePayload(targetProfile); // 合并顺序:基础Payload(msg) < Profile预设 < 显式Params覆盖 // toMinimalPayload 包含: messages, stream, max_tokens, ...params - // 我们需要把 profilePayload 塞在中间,被 params 覆盖 const minimal = requestBody.toMinimalPayload(); - // 剔除 minimal 中可能已经存在的 undefined 属性,避免覆盖 profile 的有效值 - // 但实际上 minimal 中的 ...params 是用户强指定的,应该覆盖 profile - const finalPayload = { ...profilePayload, - ...minimal, // 包含 messages, stream, max_tokens - ...options.params // 再次确保显式参数优先级最高 (minimal里其实已经含了,这里双保险) + ...minimal, + ...options.params }; const fetchOpts = { @@ -286,5 +262,34 @@ export default class ModelCaller { // Fallback return typeof data === 'object' ? JSON.stringify(data) : data; } + + /** + * 辅助方法:从 Profile 对象中提取标准生成参数 + * 用于在手动构造请求时模拟 ST 后端行为 + */ + _buildProfilePayload(targetProfile) { + return { + // 基础模型参数 + model: targetProfile.openai_model || targetProfile.model, + temperature: targetProfile.temperature, + frequency_penalty: targetProfile.frequency_penalty, + presence_penalty: targetProfile.presence_penalty, + top_p: targetProfile.top_p, + top_k: targetProfile.top_k, + min_p: targetProfile.min_p, + repetition_penalty: targetProfile.repetition_penalty, + + // 关键:OpenAI 源标记 + chat_completion_source: targetProfile.chat_completion_source || 'openai', + + // 代理设置 (如果预设里有) + reverse_proxy: targetProfile.reverse_proxy, + proxy_password: targetProfile.proxy_password, + + // 其他可能影响生成的参数 + custom_prompt_post_processing: targetProfile.custom_prompt_post_processing ?? 'strict', + include_reasoning: targetProfile.include_reasoning ?? false, + }; + } }