Repository navigation
Commit 43c320f
committed
fix(ai): 修复 DeepSeek 连通性 400 并适配 V4.1
根因(真机复现,错误体取自真实响应而非猜测):
- DeepSeek 的 response_format=json_object 有前置条件——提示词须含 "json"
字样,否则 400 invalid_request_error;探活复用业务请求构造器(恒带
json_object)而探活提示词不含 json ⇒ 每次"测试连接"必 400
- post_completions 4xx 分支只读状态码、丢弃响应体 ⇒ 用户只见
"网络错误: 请求被拒绝 HTTP 400(不重试——4xx 非瞬态)"
改动:
- 探活改最小 plain chat(无 response_format、512 token 上限、回显模型名)
- 新增 ai_request_policy(纯函数 + 单测):json 前置条件兜底 / 错误体提取 /
思考模式策略,chat 与 vision 两条构造路径共用
- 4xx/5xx 透出上游 error.message(非 JSON 体回退原文、截断 300 字符);
流式 map_status 同口径
- 模型名现代化:预设改 deepseek-flash / deepseek-v4-pro;既有安装启动期
归一退役名(仅 api.deepseek.com 端点、幂等,OpenRouter 等同名条目不动);
前端预设同步
- 思考模式:结构化 JSON 任务默认 thinking=disabled(V4 家族默认 effort=high,
实测同一请求输出 token 16 → 172 且思考与正文抢 max_tokens),AI 对话保留
provider 默认;AI_THINKING=enabled 可整体切回;单价表按 V4.1 调价更新
- 文档:知识卡(根因/探针矩阵/真机证据)+ 索引登记;豁免表按实测纠偏;
v0.22 补「工具链陷阱 3」(本机 cargo test --lib 在 DLL 加载期崩)
验证:
- cargo test --test app_lib_tests:2357 passed / 0 failed / 6 ignored(exit 0)
- cargo clippy --all-targets:exit 0,本次改动文件零新增警告
- npx tsc --noEmit 0 错;npx vitest run 103 文件 / 809 用例全绿
- 真机端到端(真实 DeepSeek API,5 组探针):探活 200、json 兜底后 200、
业务 JSON 任务 200 且 content 为合法 JSON、视觉 200(deepseek-flash 原生
多模态)、旧模型名(迁移前)仍 2001 parent 5e7f300 commit 43c320f
21 files changed
Lines changed: 933 additions & 75 deletions
File tree
- app
- src-tauri/src
- src/components
- docs
- knowledge
- bugs
- standards
- versions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
28 | 33 | | |
29 | 34 | | |
30 | 35 | | |
| |||
48 | 53 | | |
49 | 54 | | |
50 | 55 | | |
51 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
52 | 59 | | |
53 | 60 | | |
54 | 61 | | |
| |||
58 | 65 | | |
59 | 66 | | |
60 | 67 | | |
61 | | - | |
| 68 | + | |
| 69 | + | |
62 | 70 | | |
63 | 71 | | |
64 | 72 | | |
65 | 73 | | |
66 | 74 | | |
67 | | - | |
| 75 | + | |
| 76 | + | |
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
222 | 225 | | |
223 | 226 | | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
241 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
242 | 251 | | |
243 | 252 | | |
244 | 253 | | |
245 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
246 | 266 | | |
247 | 267 | | |
248 | 268 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
| 128 | + | |
127 | 129 | | |
128 | 130 | | |
129 | 131 | | |
| |||
0 commit comments