From 43a6018e6a697a39c1d9a385fc5b6ed97be22b49 Mon Sep 17 00:00:00 2001 From: lidf Date: Sun, 12 Apr 2026 15:36:55 +0800 Subject: [PATCH] feat(backend/frontend): remove AI hallucinated reportCode and use UUID programmatic assignment for absolute context integrity --- backend/gateway/platforms/deepview_sse.py | 21 ++++++++++++-------- src/app/app.ts | 5 +++-- src/app/core/chat-context.service.ts | 3 +++ src/app/pages/report-detail/report-detail.ts | 2 ++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/backend/gateway/platforms/deepview_sse.py b/backend/gateway/platforms/deepview_sse.py index 5cc0833..e19bd9a 100644 --- a/backend/gateway/platforms/deepview_sse.py +++ b/backend/gateway/platforms/deepview_sse.py @@ -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() diff --git a/src/app/app.ts b/src/app/app.ts index 770dcbf..a243820 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -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) { diff --git a/src/app/core/chat-context.service.ts b/src/app/core/chat-context.service.ts index 25b9481..3f94755 100644 --- a/src/app/core/chat-context.service.ts +++ b/src/app/core/chat-context.service.ts @@ -13,6 +13,9 @@ export class ChatContextService { /** 上下文类型:recording | client | '' */ contextType = signal<'recording' | 'client' | ''>(''); + /** 当前上下文的附加编码 (如 DW-AMXG-1234) */ + contextCode = signal(''); + /** 基于 contextId 派生 chatId */ chatId = computed(() => { const ctx = this.contextId(); diff --git a/src/app/pages/report-detail/report-detail.ts b/src/app/pages/report-detail/report-detail.ts index cd2c86b..0ece4a8 100644 --- a/src/app/pages/report-detail/report-detail.ts +++ b/src/app/pages/report-detail/report-detail.ts @@ -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() {