chengf
2025-10-11 a58221e75d2e38172533e17b6590983a9b3cabb9
修复仁智企对话保存功能问题
3个文件已修改
48 ■■■■ 已修改文件
aiflowy-modules/aiflowy-module-ai/src/main/java/tech/aiflowy/ai/config/DifyStreamClient.java 43 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aiflowy-starter/src/main/resources/application-prod.yml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
aiflowy-starter/src/main/resources/application.yml 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aiflowy-modules/aiflowy-module-ai/src/main/java/tech/aiflowy/ai/config/DifyStreamClient.java
@@ -335,6 +335,7 @@
            @Override
            public void onResponse(Call call, Response response) {
                int a = 1;
                AiMessage aiMessage = new AiMessage();
                com.agentsflex.core.llm.response.AiMessageResponse aiMessageResponse
                        = new com.agentsflex.core.llm.response.AiMessageResponse(new HistoriesPrompt(), response.message(), aiMessage);
@@ -365,16 +366,42 @@
                                // 这里需要根据具体API调整路径
                                JsonObject messageObj = gson.fromJson(data, JsonObject.class);
//                                System.out.println(messageObj);
                                if(messageObj.get("event").getAsString().equals("message_end")){
                                if(!messageObj.has("answer")){
                                    try {
                                        JsonArray asJsonArray = messageObj.getAsJsonObject("metadata").getAsJsonArray("retriever_resources");
                                        if (asJsonArray.size() > 0) {
                                            aiMessage.setFullContent("-----------------------");
                                            sb.append("\n"+aiMessage.getFullContent());
                                            emitter.send(JSON.toJSONString(aiMessage));
                                            for (int i = 0; i < asJsonArray.size(); i++) {
                                                aiMessage.setFullContent(asJsonArray.get(i).getAsJsonObject().get("document_name").getAsString());
                                                aiMessage.setContent(null);
//                                                aiMessageResponse.setMessage(aiMessage);
                                                sb.append("\n"+aiMessage.getFullContent());
                                                emitter.send(JSON.toJSONString(aiMessage));
                                            }
                                        }
                                    } catch (Exception e) {
                                        System.out.println("meizuo");
                                    }
                                    AiBotMessage aiBotMessage = new AiBotMessage();
                                    aiBotMessage.setBotId(botId);
                                    aiBotMessage.setSessionId(sessionId);
                                    aiBotMessage.setAccountId(new BigInteger(userId));
                                    aiBotMessage.setRole("assistant");
                                    String content = aiBotMessage.getContent();
                                    aiBotMessage.setContent(sb.toString());
                                    aiBotMessage.setCreated(new Date());
                                    aiBotMessage.setIsExternalMsg(1);
                                    aiBotMessageService.save(aiBotMessage);
                                    if(a == 1){
                                        a = 0;
                                        aiBotMessageService.save(aiBotMessage);
                                    }else{
                                        QueryWrapper qw = new QueryWrapper();
                                        qw.eq("content", content);
                                        aiBotMessageService.remove(qw);
                                        aiBotMessageService.save(aiBotMessage);
                                    }
//                                    System.out.println("end");
                                }else{
                                    String context = messageObj.get("answer").getAsString();
@@ -390,16 +417,16 @@
                                    aiMessage.setContent(context);
                                    aiMessageResponse.setMessage(aiMessage);
                                    if (!messageObj.get("answer").getAsString().isEmpty()) {
                                        if(!blean && aiMessage.getContent().startsWith("</details>")){
                                            blean = true;
                                            aiMessage.setContent(aiMessage.getContent().replaceAll("(?i)<[^>]*>", "\n\n"));
                                        }
                                        if(blean){
//                                        if(!blean && aiMessage.getContent().startsWith("</details>")){
//                                            blean = true;
//                                            aiMessage.setContent(aiMessage.getContent().replaceAll("(?i)<[^>]*>", "\n\n"));
//                                        }
//                                        if(blean){
                                            sb.append(aiMessage.getContent());
//                                            System.out.println(aiMessage);
                                            // 发送消息片段给前端
                                            emitter.send(JSON.toJSONString(aiMessage));
                                        }
//                                        }
                                    }
                                }
aiflowy-starter/src/main/resources/application-prod.yml
@@ -3,6 +3,6 @@
    activate:
      on-profile: prod
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/aiflowy?useInformationSchema=true&characterEncoding=utf-8
    url: jdbc:mysql://47.92.122.77:3306/aiflowy?useInformationSchema=true&characterEncoding=utf-8
    username: aiflowy
    password: 123456
aiflowy-starter/src/main/resources/application.yml
@@ -6,7 +6,8 @@
    active: dev
  datasource:
#    url: jdbc:mysql://172.18.0.2:3306/aiflowy?useInformationSchema=true&characterEncoding=utf-8
    url: jdbc:mysql://localhost:3306/aiflowy?useInformationSchema=true&characterEncoding=utf-8
#    url: jdbc:mysql://47.92.122.77:3306/aiflowy?useInformationSchema=true&characterEncoding=utf-8
    url: jdbc:mysql://47.92.134.66:3306/aiflowy?useInformationSchema=true&characterEncoding=utf-8
    username: root
    password: win2020
  servlet: