fix: v0.8.0 修订 — 思考用户意图优先 · 移除元信息硬门控 · 实施清单入库
- DeepSeek/MiMo/Agnes 移除 supportsThinking 元信息硬门控:思考参数完全遵循用户配置 (事故复盘中 vision-exp 元信息标注不支持思考、实际产生了 8189 token 推理内容, 元信息不可靠;预算耗尽由引擎降级重试兜底,元信息不符仅告警不拦截) - Ollama 保留 /api/show 能力探测门控(服务端硬协议约束:向不支持思考的模型发 think 每次请求 400,属协议正确性而非意图覆盖),探测失败 fail-open - LLM 设置提示文案修订:元信息不符仍按用户配置发送,降级重试自动兜底 - 测试契约反向钉住:vision-exp + 用户开启→照发 enabled+reasoning_effort; 关闭/未配置→显式 disabled;Ollama 探测 false→不发 think / null→fail-open - 补录 docs/v0.8.0-迭代实施清单.md(含逐项验证记录与本次修订记录; 首次提交时该文件因故未入库,本次补齐) - 验证:typecheck 0 错误 / lint 0 问题 / 系统 Node 2146 通过 / thinking 矩阵 101 用例全绿
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
/**
|
||||
* v0.8.0 P0-3: 思考参数 × 模型能力 门控矩阵。
|
||||
* v0.8.0 P0-3(修订版): 思考参数**用户意图优先**契约。
|
||||
*
|
||||
* 根因回顾:MODEL_INFO 标注 supportsThinking:false 的模型(如
|
||||
* deepseek-v4-flash-vision-exp)此前仍被发送 thinking 参数 —— 思考耗尽输出
|
||||
* 预算(8192 上限)导致 finish_reason=length 空回复、会话静默停止。
|
||||
* 本文件钉住四家 Provider 的能力门控行为与输出预算告警前置条件。
|
||||
* 修订原因:初版按 MODEL_INFO.supportsThinking 元信息硬门控,但事故复盘证明
|
||||
* 元信息不可靠 —— deepseek-v4-flash-vision-exp 标注"不支持思考"、实际却产生了
|
||||
* 8189 token 推理内容。既然引擎已有完整兜底链(最大输出上限配置 → 空响应守卫
|
||||
* → 降级重试 → OUTPUT_LENGTH_EXCEEDED 明确报错),是否开思考应由**用户决定**,
|
||||
* 适配器层只负责:①如实透传用户配置;②元信息不符时告警不拦截;③预算过小告警。
|
||||
*
|
||||
* 保留的唯一门控是 Ollama 的 /api/show capabilities 探测 —— 那是服务端实时
|
||||
* 真值且为硬协议约束(向无思考能力的模型发 think 每次请求 400),属协议
|
||||
* 正确性而非用户意图覆盖。
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
@@ -50,8 +55,8 @@ function asNative(
|
||||
).toNativeRequest.bind(adapter);
|
||||
}
|
||||
|
||||
describe('P0-3 thinking capability gate', () => {
|
||||
it('DeepSeek: vision-exp (supportsThinking:false) → thinking disabled, no reasoning_effort, max_tokens clamped to 8192', async () => {
|
||||
describe('P0-3 修订: 用户思考意图优先于模型元信息', () => {
|
||||
it('DeepSeek: vision-exp(元信息 false)+ 用户开启思考 → 照发 enabled + reasoning_effort,max_tokens 仍按模型钳制 8192', async () => {
|
||||
const adapter = new DeepSeekAdapter({
|
||||
provider: 'deepseek',
|
||||
baseURL: 'https://api.deepseek.com',
|
||||
@@ -59,54 +64,67 @@ describe('P0-3 thinking capability gate', () => {
|
||||
defaultModel: 'deepseek-v4-flash-vision-exp',
|
||||
});
|
||||
const body = asNative(adapter)(makeRequest(), false);
|
||||
expect(body.thinking).toEqual({ type: 'disabled' });
|
||||
expect(body.reasoning_effort).toBeUndefined();
|
||||
expect(body.thinking).toEqual({ type: 'enabled' });
|
||||
expect(body.reasoning_effort).toBe('max');
|
||||
expect(body.max_tokens).toBe(8192);
|
||||
});
|
||||
|
||||
it('DeepSeek: pro (supportsThinking:true) → thinking enabled + reasoning_effort mapped (max→max)', async () => {
|
||||
it('DeepSeek: 用户关闭思考 → 显式 disabled', async () => {
|
||||
const adapter = new DeepSeekAdapter({
|
||||
provider: 'deepseek',
|
||||
baseURL: 'https://api.deepseek.com',
|
||||
apiKey: 'k',
|
||||
defaultModel: 'deepseek-v4-flash-vision-exp',
|
||||
});
|
||||
const body = asNative(adapter)(
|
||||
makeRequest({ thinkingEnabled: false, thinkingEffort: undefined }),
|
||||
false,
|
||||
);
|
||||
expect(body.thinking).toEqual({ type: 'disabled' });
|
||||
expect(body.reasoning_effort).toBeUndefined();
|
||||
});
|
||||
|
||||
it('DeepSeek: 未配置 → 显式 disabled(确定性契约,不依赖服务端隐式默认)', async () => {
|
||||
const adapter = new DeepSeekAdapter({
|
||||
provider: 'deepseek',
|
||||
baseURL: 'https://api.deepseek.com',
|
||||
apiKey: 'k',
|
||||
defaultModel: 'deepseek-v4-pro',
|
||||
});
|
||||
const body = asNative(adapter)(makeRequest(), false);
|
||||
expect(body.thinking).toEqual({ type: 'enabled' });
|
||||
expect(body.reasoning_effort).toBe('max');
|
||||
const body = asNative(adapter)(makeRequest({ thinkingEnabled: undefined }), false);
|
||||
expect(body.thinking).toEqual({ type: 'disabled' });
|
||||
});
|
||||
|
||||
it('Agnes: supportsThinking:false model → enable_thinking:false', async () => {
|
||||
it('Agnes: 元信息 false + 用户开启思考 → enable_thinking:true(元信息不拦截)', async () => {
|
||||
const adapter = new AgnesAdapter({
|
||||
provider: 'agnes',
|
||||
baseURL: 'https://apihub.agnes-ai.com/v1',
|
||||
apiKey: 'k',
|
||||
defaultModel: 'agnes-2.0-flash',
|
||||
});
|
||||
// 临时改写元信息模拟"不支持思考"的模型,结束后恢复
|
||||
const table = AgnesAdapter['MODEL_INFO'] as Record<string, { supportsThinking: boolean }>;
|
||||
const original = table['agnes-2.0-flash'].supportsThinking;
|
||||
table['agnes-2.0-flash'].supportsThinking = false;
|
||||
try {
|
||||
const body = asNative(adapter)(makeRequest(), false);
|
||||
expect(body.chat_template_kwargs).toEqual({ enable_thinking: false });
|
||||
expect(body.chat_template_kwargs).toEqual({ enable_thinking: true });
|
||||
} finally {
|
||||
table['agnes-2.0-flash'].supportsThinking = original;
|
||||
}
|
||||
});
|
||||
|
||||
it('Agnes: supportsThinking:true model → enable_thinking:true', async () => {
|
||||
it('Agnes: 用户关闭思考 → enable_thinking:false(对称契约保持)', async () => {
|
||||
const adapter = new AgnesAdapter({
|
||||
provider: 'agnes',
|
||||
baseURL: 'https://apihub.agnes-ai.com/v1',
|
||||
apiKey: 'k',
|
||||
defaultModel: 'agnes-2.0-flash',
|
||||
});
|
||||
const body = asNative(adapter)(makeRequest(), false);
|
||||
expect(body.chat_template_kwargs).toEqual({ enable_thinking: true });
|
||||
const body = asNative(adapter)(makeRequest({ thinkingEnabled: false }), false);
|
||||
expect(body.chat_template_kwargs).toEqual({ enable_thinking: false });
|
||||
});
|
||||
|
||||
it('MiMo: supportsThinking:false model → thinking disabled + temperature passthrough', async () => {
|
||||
it('MiMo: 元信息 false + 用户开启思考 → thinking enabled(temperature 不传)', async () => {
|
||||
const adapter = new MimoAdapter({
|
||||
provider: 'mimo',
|
||||
baseURL: 'https://api.xiaomimimo.com/v1',
|
||||
@@ -118,14 +136,26 @@ describe('P0-3 thinking capability gate', () => {
|
||||
table['mimo-v2.5-pro'].supportsThinking = false;
|
||||
try {
|
||||
const body = asNative(adapter)(makeRequest(), false);
|
||||
expect(body.thinking).toEqual({ type: 'disabled' });
|
||||
expect(body.temperature).toBe(0);
|
||||
expect(body.thinking).toEqual({ type: 'enabled' });
|
||||
expect(body.temperature).toBeUndefined();
|
||||
} finally {
|
||||
table['mimo-v2.5-pro'].supportsThinking = original;
|
||||
}
|
||||
});
|
||||
|
||||
it('Ollama: probed no-thinking (cachedThinkingSupport=false) → no think parameter', async () => {
|
||||
it('MiMo: 用户关闭思考 → disabled + temperature/top_p 透传', async () => {
|
||||
const adapter = new MimoAdapter({
|
||||
provider: 'mimo',
|
||||
baseURL: 'https://api.xiaomimimo.com/v1',
|
||||
apiKey: 'k',
|
||||
defaultModel: 'mimo-v2.5-pro',
|
||||
});
|
||||
const body = asNative(adapter)(makeRequest({ thinkingEnabled: false }), false);
|
||||
expect(body.thinking).toEqual({ type: 'disabled' });
|
||||
expect(body.temperature).toBe(0);
|
||||
});
|
||||
|
||||
it('Ollama: 探测不支持思考(服务端硬约束)→ 不发 think 参数(唯一保留的门控)', async () => {
|
||||
const adapter = new OllamaAdapter({
|
||||
provider: 'ollama',
|
||||
baseURL: 'http://localhost:11434',
|
||||
@@ -141,7 +171,7 @@ describe('P0-3 thinking capability gate', () => {
|
||||
expect(body.think).toBeUndefined();
|
||||
});
|
||||
|
||||
it('Ollama: probe unknown (null) fails open → think parameter present', async () => {
|
||||
it('Ollama: 探测未知(null)fail-open → think 参数照发', async () => {
|
||||
const adapter = new OllamaAdapter({
|
||||
provider: 'ollama',
|
||||
baseURL: 'http://localhost:11434',
|
||||
@@ -154,6 +184,6 @@ describe('P0-3 thinking capability gate', () => {
|
||||
toNativeRequest: (r: MetonaRequest) => Promise<Record<string, unknown>>;
|
||||
}
|
||||
).toNativeRequest(makeRequest());
|
||||
expect(body.think).toBe(true); // effort=max → true
|
||||
expect(body.think).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user