feat(backend/frontend): remove AI hallucinated reportCode and use UUID programmatic assignment for absolute context integrity

This commit is contained in:
lidf 2026-04-12 15:36:55 +08:00
parent b8a541dcea
commit 43a6018e6a
4 changed files with 21 additions and 10 deletions

View File

@ -762,13 +762,12 @@ class DeepviewSSEServer:
# ── Stage 2 格式引擎: qwen3-plus via LiteLLM (JSON Schema 硬约束) ──
# 纯转换任务,不做内容创造,只做结构对齐
jsonSchema = {
"type": "object",
"properties": {
"reportCode": {"type": "string"},
"patientName": {"type": "string"},
"coreDemand": {"type": "string"},
"acceptance": {"type": "string"},
jsonSchema = {
"type": "object",
"properties": {
"patientName": {"type": "string"},
"coreDemand": {"type": "string"},
"acceptance": {"type": "string"},
"duration": {"type": "number"},
"xray": {
"type": "object",
@ -866,7 +865,7 @@ class DeepviewSSEServer:
"required": ["module1", "module2", "module3", "module4", "module5"]
}
},
"required": ["reportCode", "patientName", "coreDemand", "acceptance", "duration", "xray"]
"required": ["patientName", "coreDemand", "acceptance", "duration", "xray"]
}
try:
@ -922,6 +921,12 @@ xray.module5: track1(数组,每项含node/action/strategy/purpose), track2(数
import uuid
reportId = presetReportId if presetReportId else "rep_" + uuid.uuid4().hex[:8]
# Programmatically inject the real report identifier instead of hallucinated one
parsedData['reportCode'] = f"DW-AMXG-{reportId[4:].upper()}"
parsedData['id'] = reportId
parsedData['context_id'] = contextId
try:
from hermes_state import SessionDB
reportDb = SessionDB()

View File

@ -457,9 +457,10 @@ export class App implements OnDestroy, OnInit {
} else {
// No history, push initial greeting
const title = this.chatCtx.contextTitle();
const code = this.chatCtx.contextCode();
const greeting = this.chatCtx.contextType() === 'client'
? `医生您好,上下文已锁定${title}(全景档案)。您可以向我追问历史拒因分析或索要跨品类破冰话术。`
: `医生您好,我是本场面诊的深维特勤 AI。上下文已锁定。您可以随时向我追问改进方案。`;
? `医生您好,上下文已锁定${title}(全景档案)。您可以向我追问历史拒因分析或索要跨品类破冰话术。`
: `医生您好,我是本场面诊的深维特勤 AI。上下文 (标识:${code}) 已锁定。您可以随时向我追问改进方案。`;
this.chatMessages.push({ role: 'agent', content: greeting, isStreaming: false });
}
} catch(e) {

View File

@ -13,6 +13,9 @@ export class ChatContextService {
/** 上下文类型recording | client | '' */
contextType = signal<'recording' | 'client' | ''>('');
/** 当前上下文的附加编码 (如 DW-AMXG-1234) */
contextCode = signal<string>('');
/** 基于 contextId 派生 chatId */
chatId = computed(() => {
const ctx = this.contextId();

View File

@ -55,6 +55,7 @@ export class ReportDetail implements OnInit {
this.chatCtx.contextId.set(data.context_id || `recording:${reportId}`);
this.chatCtx.contextTitle.set(data.clientName || '未归档录音');
this.chatCtx.contextType.set('recording');
this.chatCtx.contextCode.set(data.reportCode || reportId);
// 同步写 localStorage 作为离线缓存
localStorage.setItem(`deepview_report_${reportId}`, JSON.stringify(data));
@ -79,6 +80,7 @@ export class ReportDetail implements OnInit {
this.chatCtx.contextId.set(this.report.context_id || `recording:${reportId}`);
this.chatCtx.contextTitle.set(this.report.clientName || '未归档录音');
this.chatCtx.contextType.set('recording');
this.chatCtx.contextCode.set(this.report.reportCode || reportId);
}
filterClients() {