38 lines
2.8 KiB
PHP
38 lines
2.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
// Pure synthetic preview: no application bootstrap, database, credential or network I/O.
|
|
require dirname(__DIR__, 2) . '/server/vendor/autoload.php';
|
|
use app\adminapi\logic\tcm\DiagnosisAiLogic;
|
|
use app\adminapi\service\TcmEvidenceGuard;
|
|
use app\adminapi\service\TcmClinicalFactStateGuard;
|
|
|
|
$guard = TcmEvidenceGuard::assess(['chief_complaint' => '口干两周。',
|
|
'tongue' => '舌淡红,苔薄白。', 'present_illness' => '否认明显腹胀。', 'allergy_history' => '未记录']);
|
|
$query = "[TCM_CLINICAL_RESPONSE:tcm-consultation-task-analysis-r37]\n"
|
|
. "本接诊流程不采集脉象,不设栏目、不补采、不作为诊断依据;完成本次选定任务,资料不足仍分析已知内容。\n"
|
|
. "以下全部为软件合成测试,不对应真实患者。\n任务:summary\n"
|
|
. '<CASE_DATA>主诉:口干两周。舌象:舌淡红,苔薄白。现病史:否认明显腹胀。过敏史未记录。其他资料未记录。</CASE_DATA>'
|
|
. "\n<USER_QUESTION>请根据当前病历总结病情、证候与风险,200字以内。</USER_QUESTION>";
|
|
$draft = file_get_contents(__DIR__ . '/qwen_draft_preview1.txt');
|
|
$review = TcmClinicalFactStateGuard::validate($guard['fact_state_ledger'], $draft);
|
|
$prepared = ['task' => 'summary', 'query' => $query, 'tcm_evidence_guard' => $guard];
|
|
$prompt = (new ReflectionMethod(DiagnosisAiLogic::class, 'clinicalAnswerRepairPrompt'))
|
|
->invoke(null, $prepared, '', $draft, $review['issues']);
|
|
file_put_contents(__DIR__ . '/qwen_preview_repair_query.txt', $prompt);
|
|
file_put_contents(__DIR__ . '/qwen_preview1_guard.safe.json', json_encode([
|
|
'synthetic_only' => true, 'valid' => $review['valid'], 'issue_codes' => array_column($review['issues'], 'code'),
|
|
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
|
echo json_encode(['valid' => $review['valid'], 'issue_codes' => array_column($review['issues'], 'code'),
|
|
'repair_prompt_bytes' => strlen($prompt)], JSON_UNESCAPED_UNICODE) . "\n";
|
|
if (is_file(__DIR__ . '/qwen_draft_preview2_correction.txt')) {
|
|
$corrected = file_get_contents(__DIR__ . '/qwen_draft_preview2_correction.txt');
|
|
$review2 = TcmClinicalFactStateGuard::validate($guard['fact_state_ledger'], $corrected);
|
|
$pulse = \app\adminapi\service\TcmConsultationPulsePolicy::validate($guard['fact_state_ledger'], $corrected);
|
|
$safe = ['synthetic_only' => true, 'fact_guard_valid' => $review2['valid'], 'pulse_policy_valid' => $pulse['valid'],
|
|
'issue_codes' => array_column($review2['issues'], 'code'), 'characters' => mb_strlen($corrected, 'UTF-8'),
|
|
'production_end_to_end' => false, 'preview_conversation_has_prior_context' => true];
|
|
file_put_contents(__DIR__ . '/qwen_preview2_guard.safe.json', json_encode($safe, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
|
echo json_encode($safe, JSON_UNESCAPED_UNICODE) . "\n";
|
|
}
|