Sfoglia il codice sorgente

历史详情恢复

liuchengsen 4 settimane fa
parent
commit
39f4661c96

+ 5 - 4
backend-java/src/main/java/com/pharmacopoeia/controller/ChatController.java

@@ -15,7 +15,6 @@ import org.springframework.http.codec.ServerSentEvent;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.web.bind.annotation.*;
 import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
 
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.web.multipart.MultipartFile;
@@ -473,7 +472,9 @@ public class ChatController {
                                 StringBuilder ocrBuilder = new StringBuilder();
                                 for (ServerSentEvent<String> e : events) {
                                     String d = e.data();
-                                    if (d != null && !d.equals("\n\n")) ocrBuilder.append(d);
+                                    if (d != null && !"\n\n".equals(d)) {
+                                        ocrBuilder.append(d);
+                                    }
                                 }
                                 String mediaOcr = ocrBuilder.toString().trim();
                                 // 不重复发送 OCR 事件(已经通过 analyzeMediaStream 实时发送过了)
@@ -740,9 +741,9 @@ public class ChatController {
                     if (sectionDisplay == null || sectionDisplay.isEmpty()) {
                         sectionDisplay = realSection(content, storedSection);
                     }
-                    // 跳过"正文"类无意义栏目
+                    // 把"正文"替换为更友好的显示名
                     if ("正文".equals(sectionDisplay)) {
-                        return null;
+                        sectionDisplay = "药典正文";
                     }
 
                     // 构建完整来源引用

+ 2 - 1
backend-java/src/main/java/com/pharmacopoeia/service/ChatPersistenceService.java

@@ -128,7 +128,8 @@ public class ChatPersistenceService {
             result.add(Map.of(
                     "role", msg.getRole(),
                     "content", msg.getContent(),
-                    "intent", msg.getIntent() != null ? msg.getIntent() : ""
+                    "intent", msg.getIntent() != null ? msg.getIntent() : "",
+                    "sources", msg.getSourcesList()
             ));
         }
         return result;

+ 1 - 1
backend-java/src/main/java/com/pharmacopoeia/service/PromptService.java

@@ -37,7 +37,7 @@ public class PromptService {
             请据此准确引用原文,保留数字、剂量、单位的完整性和准确性。
             回答格式(紧凑排版,段落标题后直接接内容,不得有空行):
             【结论】   2-3句话概括。
-            【详细信息】分栏目引用原文,标注来源版本和栏目名称。
+            【详细信息】分栏目逐一引用原文(不可省略任何检索到的栏目),标注来源版本和栏目名称。
             【来源明细】列出本题引用的所有资料名称及出处(含版本号如"2025版药典一部"),相同来源只列一次,禁止重复。
             """ + COMPLIANCE + AI_DISCLAIMER;
 

+ 6 - 0
static/index.html

@@ -342,6 +342,12 @@
         var tag=m.intent||'';
         var tagHtml=tag?'<div class="tag '+tagClass(tag)+'">'+intentLabel(tag)+'</div>':'<div class="tag tag-fallback">AI 药典助手</div>';
         div.innerHTML=tagHtml+'<div class="content">'+md2html(m.content)+'</div>';
+        // 恢复历史记录中的来源引用
+        if (m.sources && m.sources.length) {
+          sourcesData = m.sources;
+          div.innerHTML += buildSourceTags();
+          sourcesData = [];
+        }
       }
       document.getElementById('chat').appendChild(div);
     }