Преглед изворни кода

ai客户意向度分析新key切换及后续代码优化

lk пре 3 дана
родитељ
комит
44bc4845dd

+ 3 - 0
fs-service/src/main/java/com/fs/config/saas/ProjectConfig.java

@@ -318,6 +318,9 @@ public class ProjectConfig {
 
         @JsonProperty("commonApi")
         private String commonApi;
+
+        @JsonProperty("voiceApiOld")
+        private String voiceApiOld;
     }
 
     @Data

+ 23 - 23
fs-service/src/main/java/com/fs/crm/service/impl/CrmCustomerAnalyzeServiceImpl.java

@@ -555,7 +555,7 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
         requestParam.put("modelType","客户意向度");
 //        log.info("请求参数:{}", requestParam);
 
-        R aiResponse = CrmCustomerAiTagUtil.callAiService(requestParam, chatId,INTENTION_DEGREE_KEY);
+        R aiResponse = CrmCustomerAiTagUtil.callAiServiceIntegration(requestParam, chatId,INTENTION_DEGREE_KEY);
 //        JSONObject root = JSON.parseObject(JSONUtil.toJsonStr(aiResponse));
 //        System.out.println(aiResponse);
 // 获取 data.responseData
@@ -567,28 +567,28 @@ public class CrmCustomerAnalyzeServiceImpl extends ServiceImpl<CrmCustomerAnalyz
 
             if (choices.isArray() && choices.size() > 0) {
                 JsonNode contentNode = choices.get(0).path("message").path("content");
-
-                if (contentNode.isTextual()) {
-                    String contentStr = contentNode.asText();
-                    // 将content字符串解析为JsonNode
-                    JsonNode contentArray = mapper.readTree(contentStr);
-
-                    if (contentArray.isArray() && contentArray.size() > 1) {
-                        JsonNode secondElement = contentArray.get(1);
-                        JsonNode textNode = secondElement.path("text");
-
-                        if (!textNode.isMissingNode()) {
-                            JsonNode contentInnerNode = textNode.path("content");
-
-                            if (contentInnerNode.isTextual()) {
-                                String innerJsonStr = contentInnerNode.asText();
-                                JsonNode innerJson = mapper.readTree(innerJsonStr);
-                                JsonNode userInfo = innerJson.path("userIntent");
-                                result = userInfo.asText();
-                            }
-                        }
-                    }
-                }
+                result = contentNode.asText();
+//                if (contentNode.isTextual()) {
+//                    String contentStr = contentNode.asText();
+//                    // 将content字符串解析为JsonNode
+//                    JsonNode contentArray = mapper.readTree(contentStr);
+//
+//                    if (contentArray.isArray() && contentArray.size() > 1) {
+//                        JsonNode secondElement = contentArray.get(1);
+//                        JsonNode textNode = secondElement.path("text");
+//
+//                        if (!textNode.isMissingNode()) {
+//                            JsonNode contentInnerNode = textNode.path("content");
+//
+//                            if (contentInnerNode.isTextual()) {
+//                                String innerJsonStr = contentInnerNode.asText();
+//                                JsonNode innerJson = mapper.readTree(innerJsonStr);
+//                                JsonNode userInfo = innerJson.path("userIntent");
+//                                result = userInfo.asText();
+//                            }
+//                        }
+//                    }
+//                }
             }
 
         } catch (Exception e) {

+ 27 - 0
fs-service/src/main/java/com/fs/crm/utils/CrmCustomerAiTagUtil.java

@@ -154,6 +154,33 @@ public class CrmCustomerAiTagUtil {
             if(null != projectConfig && null != projectConfig.getIpad()){
                 aiApiUrl = projectConfig.getIpad().getAiApi();
             }
+//            return chatService.initiatingTakeChat(param, aiHost.getAiApi(), appKey);
+            return chatService.initiatingTakeChat(param, aiApiUrl, appKey);
+        } catch (Exception e) {
+            throw new RuntimeException("AI服务调用失败", e);
+        }
+    }
+    public static R callAiServiceIntegration(Map<String, Object> requestParam, Long logId,String appKey) {
+        try {
+            String requestJson = mapper.writeValueAsString(requestParam);
+
+            ChatParam param = new ChatParam();
+            param.setChatId(logId.toString());
+            param.setStream(false);
+            param.setDetail(true);
+            ChatParam.Message message = new ChatParam.Message();
+            List<ChatParam.Message> messageList = new ArrayList<ChatParam.Message>();
+            message.setContent(requestJson);
+            message.setRole("user");
+            messageList.add(message);
+            param.setMessages(messageList);
+            ChatService chatService = SpringUtils.getBean(ChatService.class);
+            AiHostProper aiHost = SpringUtils.getBean(AiHostProper.class);
+            com.fs.config.saas.ProjectConfig projectConfig = com.fs.config.saas.ProjectConfig.getFromDB(sysConfigMapper);
+            String aiApiUrl ="";
+            if(null != projectConfig && null != projectConfig.getIpad()){
+                aiApiUrl = projectConfig.getIpad().getVoiceApiOld();
+            }
 //            return chatService.initiatingTakeChat(param, aiHost.getAiApi(), appKey);
             return chatService.initiatingTakeChat(param, aiApiUrl, appKey);
         } catch (Exception e) {