已开处方列表提速;处方 AI 拒答带全部候选键时按拒答处理

- 置顶风险处方改为从订单表出发计算并缓存 60 秒,分页只查 ID,不再整表扫描与排序
- 列表行不再返回 doctor_signature,查看/编辑仍另取详情
- 模型拒绝开方时把候选键置空返回,不再判为 INVALID_REPORT_OUTPUT,可进入追问

Co-Authored-By: Claude Opus 5 <[EMAIL]>
This commit is contained in:
Your Name
2026-12-04 15:01:39 +08:00
co-authored by Claude Opus 5
parent 63e52f6273
commit 14936cb28a
3 changed files with 118 additions and 42 deletions
@@ -161,6 +161,29 @@ rxGeneratorExpect(!isset($refusalProgress['steps']['final']) && !isset($refusalP
$modelWithheld = PrescriptionAiGenerator::generateWithTransport('qwen', $noncriticalContext, $alwaysWithheld, null, $withholdingConfig);
rxGeneratorExpect($modelWithheld['ok'] && $modelWithheld['candidate']['status'] === 'withheld_for_risk',
'configured withholding still honours model-identified safety uncertainty');
// OpenAI 实测的拒答形态:带上全部候选键并置空。应按拒答处理并进入追问,而不是整份报告格式错误。
$verboseRefusal = $final;
$verboseRefusal['candidate'] = ['status' => 'insufficient_data', 'reason' => '无法确定脏腑定位。', 'prescription_name' => null,
'prescription_type' => null, 'dose_basis' => null, 'herbs' => [], 'usage_instruction' => null, 'times_per_day' => null,
'usage_days' => null, 'rationale' => '暂无方义。', 'risk_warnings' => ['核对合并用药。'], 'evidence_references' => ['diagnoses:1']];
$verboseParsed = PrescriptionAiGenerator::parseFinal(rxGeneratorJson($verboseRefusal), ['diagnoses:1']);
rxGeneratorExpect($verboseParsed !== null && $verboseParsed['candidate'] === ['status' => 'insufficient_data', 'reason' => '无法确定脏腑定位。', 'herbs' => []],
'a refusal carrying the full candidate key set is normalised to status, reason and empty herbs');
$smuggled = $verboseRefusal;
$smuggled['candidate']['herbs'] = [$candidate['herbs'][0]];
rxGeneratorExpect(PrescriptionAiGenerator::parseFinal(rxGeneratorJson($smuggled), ['diagnoses:1']) === null,
'a refusal that still lists herbs stays invalid');
$verboseInsistCalls = 0;
$verboseInsist = static function ($model, $prompt, $files, $user) use ($stub, $final, $verboseRefusal, &$verboseInsistCalls): array {
if (!str_contains($prompt, '阶段=final')) {
return $stub($model, $prompt, $files, $user);
}
$verboseInsistCalls++;
return ['ok' => true, 'content' => rxGeneratorJson(str_contains($prompt, '上一次回答没有给出候选处方') ? $final : $verboseRefusal)];
};
$verboseResult = PrescriptionAiGenerator::generateWithTransport('openai', $noncriticalContext, $verboseInsist);
rxGeneratorExpect($verboseResult['ok'] && $verboseResult['candidate']['status'] === 'available_for_review' && $verboseInsistCalls === 2,
'a verbose refusal reaches the refusal re-ask instead of burning a format repair');
$oldPolicyContext = $context;
$oldPolicyContext['_progress'] = $saved;
$oldPolicyContext['_progress']['prompt_version'] = 'manual-prescription-independent-v1';