From 4c61837b93e0818715bbe007845c2076cadb1fc1 Mon Sep 17 00:00:00 2001 From: Silence_Lurker Date: Tue, 20 Jan 2026 10:30:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=5FbuildProfilePayload=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E5=85=A8=E9=9D=A2=E7=BB=A7=E6=89=BF?= =?UTF-8?q?=20Profile=20=E5=B1=9E=E6=80=A7=E5=B9=B6=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E5=8C=96=E5=85=B3=E9=94=AE=E5=AD=97=E6=AE=B5=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E5=8F=82=E6=95=B0=E5=AE=8C=E6=95=B4=E6=80=A7=E5=92=8C?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SL/bus/api/ModelCaller.js | 48 +++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/SL/bus/api/ModelCaller.js b/SL/bus/api/ModelCaller.js index 65303f4..4b024fb 100644 --- a/SL/bus/api/ModelCaller.js +++ b/SL/bus/api/ModelCaller.js @@ -268,28 +268,32 @@ export default class ModelCaller { * 用于在手动构造请求时模拟 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, - }; + // 1. 全量继承 Profile 属性,防止遗漏自定义字段 (如 custom_url, user_name 等) + const payload = { ...targetProfile }; + + // 2. 规范化关键字段 + // ST 的 Profile 里模型名可能叫 openai_model, claude_model 等,统一映射为 model + if (!payload.model) { + payload.model = payload.openai_model || payload.claude_model || payload.mistral_model || payload.text_generation_webui_model || ''; + } + + // 3. 确保 chat_completion_source 存在 + if (!payload.chat_completion_source) { + payload.chat_completion_source = 'openai'; + } + + // 4. 处理 URL 映射 (OpenAI 兼容接口通常需要 reverse_proxy) + // 如果 Profile 里只有 custom_url 或 api_url,尝试映射给 reverse_proxy + if (!payload.reverse_proxy && (payload.custom_url || payload.api_url)) { + payload.reverse_proxy = payload.custom_url || payload.api_url; + } + + // 5. 补充默认采样参数 (如果 Profile 里完全缺失) + if (payload.temperature === undefined) payload.temperature = 1; + if (payload.max_tokens === undefined) payload.max_tokens = 2000; + // 注意:top_p 等如果为 undefined,通常后端会用默认值,这里暂不强行赋值,以免覆盖后端逻辑 + + return payload; } }