Bläddra i källkod

调整多模态支持

liuchengsen 1 månad sedan
förälder
incheckning
428a144e82

+ 18 - 6
backend-java/src/main/java/com/pharmacopoeia/controller/ChatController.java

@@ -591,9 +591,13 @@ public class ChatController {
 
                     // 构建完整来源引用
                     StringBuilder sourceBuilder = new StringBuilder();
-                    if (!sourceVersion.isEmpty()) sourceBuilder.append(sourceVersion);
+                    if (!sourceVersion.isEmpty()) {
+                        sourceBuilder.append(sourceVersion);
+                    }
                     if (!sourceVolume.isEmpty()) {
-                        if (!sourceBuilder.isEmpty()) sourceBuilder.append(" ");
+                        if (!sourceBuilder.isEmpty()) {
+                            sourceBuilder.append(" ");
+                        }
                         sourceBuilder.append(sourceVolume);
                     }
                     String fullSource = sourceBuilder.toString();
@@ -614,7 +618,9 @@ public class ChatController {
     }
 
     private String extractDrugName(String content) {
-        if (content == null) return "";
+        if (content == null) {
+            return "";
+        }
         int start = content.indexOf("【");
         int end = content.indexOf(" - ");
         if (start >= 0 && end > start) {
@@ -625,9 +631,13 @@ public class ChatController {
 
     /** 从 content 文本中提取真实 section(兜底"正文") */
     private String realSection(String content, String storedSection) {
-        if (!"正文".equals(storedSection) || content == null) return storedSection;
+        if (!"正文".equals(storedSection) || content == null) {
+            return storedSection;
+        }
         int sep = content.indexOf(" - ");
-        if (sep < 0) return storedSection;
+        if (sep < 0) {
+            return storedSection;
+        }
         int end = content.indexOf("】", sep);
         if (end > sep) {
             return content.substring(sep + 3, end).trim();
@@ -636,7 +646,9 @@ public class ChatController {
     }
 
     private String cleanAnswer(String text) {
-        if (text == null) return "";
+        if (text == null) {
+            return "";
+        }
         // 去除多余空白行(保留单个换行),修复 Qwen 常见格式问题
         return text
                 .replace("\r\n", "\n")

+ 5 - 2
backend-java/src/main/java/com/pharmacopoeia/service/LLMService.java

@@ -11,6 +11,7 @@ import org.springframework.web.reactive.function.client.WebClient;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -287,7 +288,9 @@ public class LLMService {
 
     public List<Float> embed(String text) {
         List<List<Float>> result = embedBatch(List.of(text));
-        if (result.isEmpty()) return List.of();
+        if (result.isEmpty()) {
+            return List.of();
+        }
         return result.get(0);
     }
 
@@ -362,7 +365,7 @@ public class LLMService {
                         for (JsonNode e : embeddings) {
                             List<Float> vec = new ArrayList<>();
                             for (JsonNode v : e.get("embedding")) {
-                                vec.add(v.asDouble().floatValue());
+                                vec.add((float) v.asDouble());
                             }
                             result.add(vec);
                         }