Browse Source

修改历史会话根据角色返回内容格式,开启联网搜索功能

zhaojinyu 2 weeks ago
parent
commit
ba5342d395

+ 1 - 0
service-ai/service-ai-biz/src/main/java/com/usky/ai/controller/web/AiChatController.java

@@ -135,6 +135,7 @@ public class AiChatController {
                 .topP(0.8)
                 .apiKey(apiKey)
                 .incrementalOutput(true) // 开启增量输出
+                .enableSearch(true)  //联网搜索
                 .build();
 
         String finalSessionId = sessionId;

+ 8 - 3
service-ai/service-ai-biz/src/main/java/com/usky/ai/controller/web/AiSessionController.java

@@ -36,7 +36,8 @@ public class AiSessionController {
         Long userId = SecurityUtils.getUserId();
         return getSessionsByUserId(userId);
     }
-    public List<AiSession> getSessionsByUserId(@PathVariable Long userId) {
+
+    public List<AiSession> getSessionsByUserId(Long userId) {
         List<AiSession> sessions = aiSessionMapper.findByUserId(userId);
 
         for (AiSession session : sessions) {
@@ -50,15 +51,19 @@ public class AiSessionController {
                 userItem.setUserId(question.getUserId());
                 userItem.setUserName(question.getUserName());
                 userItem.setAskTime(question.getAskTime());
+                // 不设置 reasoningContent,因为 role 是 user
+
+                itemList.add(userItem);
 
-                AiQuestionItem assistantItem = new AiQuestionItem("assistant", question.getAnswer());
+                AiQuestionItem assistantItem = new AiQuestionItem("assistant", null); // 初始化 content 为 null
                 assistantItem.setId(question.getId());
                 assistantItem.setSessionId(question.getSessionId());
                 assistantItem.setUserId(question.getUserId());
                 assistantItem.setUserName(question.getUserName());
                 assistantItem.setAskTime(question.getAskTime());
+                assistantItem.setReasoningContent(question.getAnswer()); // 设置 reasoningContent
+                // 不设置 content,因为 role 是 assistant
 
-                itemList.add(userItem);
                 itemList.add(assistantItem);
             }
 

+ 5 - 0
service-ai/service-ai-biz/src/main/java/com/usky/ai/service/AiQuestionItem.java

@@ -9,6 +9,7 @@ public class AiQuestionItem {
     private String userName;
     private String role;
     private String content;
+    private String reasoningContent;
     private LocalDateTime askTime;
 
     public AiQuestionItem(String role, String content) {
@@ -40,6 +41,10 @@ public class AiQuestionItem {
 
     public void setContent(String content) { this.content = content; }
 
+    public String getReasoningContent() { return reasoningContent; }
+
+    public void setReasoningContent(String reasoningContent) { this.reasoningContent = reasoningContent; }
+
     public LocalDateTime getAskTime() { return askTime; }
 
     public void setAskTime(LocalDateTime askTime) { this.askTime = askTime; }