Ver Fonte

fix 镜像系统对话次数同步

chenbiao há 2 anos atrás
pai
commit
610dcd0c36

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/chatgpt/ChatGptAccountService.java

@@ -32,7 +32,7 @@ public interface ChatGptAccountService {
      * @param model 对话模型
      * @return 是否限制
      */
-    ConversationLimitResponse conversationLimit(String userToken, String model, String carId, ChatgptUser user);
+    ConversationLimitResponse conversationLimit(String userToken, String model, String carId, ChatgptUser user, Boolean isCar);
 
     void saveConversationRecord(String userToken, ConversationRequest conversationRequest);
 

+ 15 - 5
netflix-service/src/main/java/com/cyksj/service/chatgpt/impl/ChatGptAccountServiceImpl.java

@@ -400,18 +400,28 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
 
 
     @Override
-    public ConversationLimitResponse conversationLimit(String userToken, String model, String carId, ChatgptUser chatgptUser) {
+    public ConversationLimitResponse conversationLimit(String userToken, String model, String carId, ChatgptUser chatgptUser, Boolean isCar) {
         ConversationLimitResponse conversationLimitResponse = new ConversationLimitResponse();
         conversationLimitResponse.setLimited(false);
         if (!"text-davinci-002-render-sha".equals(model)) {
             //如果不为车队 直接返回
-            if (!chatgptUser.getIsCar()) {
-                return conversationLimitResponse;
+            if (chatgptUser.getIsCar()) {
+                conversationLimitResponse = isConversationAllowed(userToken, chatgptUser.getLimitNum(), chatgptUser.getLimitTime());
+            }
+            if(carId == null){
+                if (StringUtils.isNotBlank(userToken)) {
+                    if (chatgptUser.getSessionId() != null) {
+                        ChatgptSession chatgptSession = chatgptSessionMapper.selectById(chatgptUser.getSessionId());
+                        if(chatgptSession != null){
+                            carId = chatgptSession.getCarId();
+                        }
+                    }
+                }
             }
-            conversationLimitResponse = isConversationAllowed(userToken, chatgptUser.getLimitNum(), chatgptUser.getLimitTime());
             //车队次数记录
+            String finalCarId = carId;
             TASK_EXECUTOR.execute(() -> {
-                cardConversationRecord(carId);
+                cardConversationRecord(finalCarId);
             });
         }
 

+ 3 - 2
netflix-web/src/main/java/com/cyksj/web/controller/mirror/MirrorController.java

@@ -124,7 +124,7 @@ public class MirrorController {
      * 会话限制
      */
     @RequestMapping("/gpt/conversation/limit")
-    public void conversationLimit(@RequestBody ConversationRequest conversationRequest) {
+    public void conversationLimit(@RequestParam(value = "isCar", defaultValue = "false") Boolean isCar, @RequestBody ConversationRequest conversationRequest) {
         //1.从request获取请求头Authorization 并取 值内 'Bearer ' 后的值为usertoken
         String authorization = request.getHeader("Authorization");
         String carid = request.getHeader("Carid");
@@ -139,7 +139,7 @@ public class MirrorController {
         if(StringUtils.isNotBlank(conversationRequest.getCarId())){
             //4.获取gpt-4 的规则限制
             //text-davinci-002-render-sha 3.5
-            ConversationLimitResponse conversationLimitResponse = chatGptAccountService.conversationLimit(userToken, conversationRequest.getModel(), conversationRequest.getCarId(), user);
+            ConversationLimitResponse conversationLimitResponse = chatGptAccountService.conversationLimit(userToken, conversationRequest.getModel(), conversationRequest.getCarId(), user, isCar);
 
             OutputStream out = null;
             String messgae = "";
@@ -163,6 +163,7 @@ public class MirrorController {
                 IoKit.close(out);
             }
         }
+
         //记录提问时间,车次,标题和模型
         TASK_EXECUTOR.execute(() -> {
             chatGptAccountService.saveConversationRecord(userToken, conversationRequest);