Browse Source

1.调整聊天记录+ai销售信息发送格式

jzp 2 months ago
parent
commit
2e9f038817

+ 3 - 2
fs-service/src/main/java/com/fs/fastGpt/domain/FastGptChatConversation.java

@@ -1,13 +1,14 @@
 package com.fs.fastGpt.domain;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.Data;
 
 @Data
 public class FastGptChatConversation {
     private JSONObject userInfo;
-    private JSONObject aiInfo;
-    private JSONObject history;
+    private String aiInfo;
+    private JSONArray history;
     private String isRepository;
     private String userContent;
     private String aiContent;

+ 19 - 10
fs-service/src/main/java/com/fs/fastGpt/service/impl/AiHookServiceImpl.java

@@ -1633,9 +1633,12 @@ public class AiHookServiceImpl implements AiHookService {
     private void addPromptWordNew(List<ChatParam.Message> messageList,String count,Long extId,FastGptRole role,FastGptChatSession fastGptChatSession){
 
         FastGptChatConversation conversation = new FastGptChatConversation();
-        conversation.setAiInfo(new com.alibaba.fastjson.JSONObject());
         conversation.setUserInfo(new com.alibaba.fastjson.JSONObject());
-        conversation.setHistory(new com.alibaba.fastjson.JSONObject());
+        conversation.setHistory(new com.alibaba.fastjson.JSONArray());
+
+        if(role.getReminderWords() != null && !role.getReminderWords().isEmpty()){
+            conversation.setAiInfo(role.getReminderWords());
+        }
 
         //组装客户信息
         String sessionUserInfo = fastGptChatSession.getUserInfo();
@@ -1666,7 +1669,7 @@ public class AiHookServiceImpl implements AiHookService {
 
         List<FastGptChatMsg> msgs=fastGptChatMsgService.selectFastGptChatMsgByMsgSessionIdAndExtId(fastGptChatSession.getSessionId(),extId);
         if (!msgs.isEmpty()){
-            com.alibaba.fastjson.JSONObject history = conversation.getHistory();
+            com.alibaba.fastjson.JSONArray historyArray = new com.alibaba.fastjson.JSONArray();
             Collections.reverse(msgs);
             msgs.remove(msgs.size() - 1);
             for (FastGptChatMsg msg : msgs) {
@@ -1677,9 +1680,12 @@ public class AiHookServiceImpl implements AiHookService {
                         continue;
                     }
                 }
-                history.put(sendType==1?"user":"ai",content);
+                com.alibaba.fastjson.JSONObject msgObj = new com.alibaba.fastjson.JSONObject();
+                msgObj.put("role", sendType==1?"user":"ai");
+                msgObj.put("content", content);
+                historyArray.add(msgObj);
             }
-            conversation.setHistory(history);
+            conversation.setHistory(historyArray);
         }
 
         if (count!=null&& !count.isEmpty()){
@@ -1698,9 +1704,8 @@ public class AiHookServiceImpl implements AiHookService {
     private void addPromptWord(List<ChatParam.Message> messageList,String count,Long extId,String words,String countInfo,Long sessionId){
 
         FastGptChatConversation conversation = new FastGptChatConversation();
-        conversation.setAiInfo(new com.alibaba.fastjson.JSONObject());
         conversation.setUserInfo(new com.alibaba.fastjson.JSONObject());
-        conversation.setHistory(new com.alibaba.fastjson.JSONObject());
+        conversation.setHistory(new com.alibaba.fastjson.JSONArray());
 
 
         // 这里获取后台的提示词进行匹配
@@ -1756,19 +1761,23 @@ public class AiHookServiceImpl implements AiHookService {
 
         List<FastGptChatMsg> msgs=fastGptChatMsgService.selectFastGptChatMsgByMsgSessionIdAndExtId(sessionId,extId);
         if (!msgs.isEmpty()){
-            com.alibaba.fastjson.JSONObject history = conversation.getHistory();
+            com.alibaba.fastjson.JSONArray historyArray = new com.alibaba.fastjson.JSONArray();
             Collections.reverse(msgs);
             msgs.remove(msgs.size() - 1);
             for (FastGptChatMsg msg : msgs) {
                 Integer sendType = msg.getSendType();
                 String content = msg.getContent();
                 if(sendType!=1){
-                    if (content!=null&&content.length()>150){
+                    if (content!=null&&content.length()>500){
                         continue;
                     }
                 }
-                history.put(sendType==1?"user":"ai",content);
+                com.alibaba.fastjson.JSONObject msgObj = new com.alibaba.fastjson.JSONObject();
+                msgObj.put("role", sendType==1?"user":"ai");
+                msgObj.put("content", content);
+                historyArray.add(msgObj);
             }
+            conversation.setHistory(historyArray);
         }
 
         if (count!=null&& !count.isEmpty()){