fix(ai): DeepSeek 真实联调——响应健壮性与筛选替换提示词
Verify / verify (pull_request) Failing after 1s
AI Review / review (pull_request) Successful in 12s
Verify / verify (push) Failing after 32s

- assistant 解析兼容:支持 in_progress 异步轮询(DeepSeek 偶发)、
  去除 markdown 代码围栏、整体失败重试一次后才报 502
- 系统提示词增加筛选替换规则与示例:用户明确提到某维度新取值时替换
  现有筛选而非叠加(实测修复“口腔+健康管理”空范围问题)
- KPI 数字字号改为容器查询 clamp(13px,1.9cqw,21px),窄宽度下
  完整显示金额而非省略号截断
- 新增 in_progress 轮询 + 重试的单测(test_assistant_api)

验证:pytest 82 passed;DeepSeek 真实调用 5/5 成功(异常/证据/
筛选替换三种意图);Playwright 回归通过
This commit was merged in pull request #9.
This commit is contained in:
Jayway Liu
2026-11-01 04:43:28 +08:00
parent 2a83de21d9
commit 3c3799910d
4 changed files with 125 additions and 42 deletions
+53
View File
@@ -43,6 +43,59 @@ def completed_response(intent=None):
return Response()
def test_model_intent_polls_in_progress_and_retries_invalid_response(workspace, settings):
ds, _, _, _, _ = workspace
settings.AI_ENABLED = True
settings.OPENAI_MODEL = "test-model"
settings.OPENAI_API_KEY = "test-key"
polled = {"n": 0, "posts": 0}
class InProgress:
def raise_for_status(self):
return None
def json(self):
return {"status": "in_progress", "id": "resp-1"}
class ClientMock:
def __init__(self, *args, **kwargs):
pass
def __enter__(self):
return self
def __exit__(self, *args):
return False
def post(self, *args, **kwargs):
polled["posts"] += 1
# 第一次 POST 返回损坏文本(触发整体重试),第二次 POST 返回 in_progress
if polled["posts"] == 1:
class Bad:
def raise_for_status(self):
return None
def json(self):
return {
"status": "completed",
"output": [{"content": [{"type": "output_text", "text": "not-json"}]}],
}
return Bad()
return InProgress()
def get(self, *args, **kwargs):
polled["n"] += 1
assert args[0].endswith("/responses/resp-1")
return completed_response({"action": "anomalies", "metric": "revenue", "group": "department", "filters": []})
with patch("finance.assistant.httpx.Client", ClientMock):
intent = model_intent("看异常", ds, {"metric": "revenue", "group": "department", "filters": {}})
assert intent["action"] == "anomalies"
assert polled["n"] == 1
def test_ai_config_requires_full_admin_and_masks_key(workspace):
ds, member, client, _, _ = workspace
url = "/api/ai-config"