Prechádzať zdrojové kódy

添加dify 下载的url配置
修改httpservice get下载的方法

183207892172 2 dní pred
rodič
commit
4125fc7d55

+ 1 - 0
java/storlead-api/src/main/resources/application-dev.yml

@@ -191,6 +191,7 @@ logging:
 environment: test
 dify:
   base-url: http://47.112.196.2:11434/v1/
+  download-url: http://47.112.196.2:11435
   dataset-api-key: dataset-qfhXMNcjsRSwN5CK6aoWx3hl
   app-keys:
     chat: app-1-qfhXMNcjsRSwN5CK6aoWx3hl  #对话

+ 1 - 0
java/storlead-api/src/main/resources/application-prod.yml

@@ -241,6 +241,7 @@ file:
 
 dify:
   base-url: http://47.112.196.2:11434/v1/
+  download-url: http://47.112.196.2:11435
   dataset-api-key: dataset-qfhXMNcjsRSwN5CK6aoWx3hl
   app-keys:
     chat: app-1-qfhXMNcjsRSwN5CK6aoWx3hl  #对话

+ 12 - 11
java/storlead-api/src/main/resources/application-test.yml

@@ -21,7 +21,7 @@ spring:
     multipart:
       max-file-size: 20MB
       max-request-size: 20MB
-  ## quartz摰𡁏𧒄隞餃𦛚,��鍂�唳旿摨𤘪䲮?
+  ## quartz摰𡁏𧒄隞餃𦛚,��鍂�唳旿摨𤘪䲮嚙�?
   #  quartz:
   #    job-store-type: jdbc
   #json �園𡢿�喟�銝�頧祆揢
@@ -32,7 +32,7 @@ spring:
     proxy-target-class: true
   #�滨蔭freemarker
   freemarker:
-    # 霈曄蔭璅⊥踎�𡒊��?
+    # 霈曄蔭璅⊥踎�𡒊��?
     suffix: .ftl
     # 霈曄蔭��﹝蝐餃�
     content-type: text/html
@@ -44,7 +44,7 @@ spring:
     # 霈曄蔭ftl��辣頝臬�
     template-loader-path:
       - classpath:/templates
-  # 霈曄蔭�蹱���隞嗉楝敺��js,css? #redis �滨蔭
+  # 霈曄蔭�蹱���隞嗉楝敺��js,css嚙�? #redis �滨蔭
   redis:
     host: test1.storlead.com
     port: 59394
@@ -64,13 +64,13 @@ spring:
     exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
   datasource:
     dynamic:
-      druid: # �典�druid��㺭嚗𣬚�憭折����澆�暺䁅恕靽脲�銝��氬�?�啣歇�舀�����啣�銝?銝齿�璆𡁜鉄銋劐�閬�僚霈曄蔭)
+      druid: # �典�druid��㺭嚗𣬚�憭折����澆�暺䁅恕靽脲�銝��湛蕭?�啣歇�舀�����啣�嚙�?銝齿�璆𡁜鉄銋劐�閬�僚霈曄蔭)
         # 餈墧𦻖瘙删��滨蔭靽⊥�
-        # �嘥��硋之撠𧶏���撠𧶏���?
+        # �嘥��硋之撠𧶏���撠𧶏���嚙�?
         initial-size: 5
         min-idle: 5
         maxActive: 20
-        # �滨蔭�瑕�餈墧𦻖蝑匧�頞�𧒄��𧒄�?
+        # �滨蔭�瑕�餈墧𦻖蝑匧�頞�𧒄��𧒄�?
         maxWait: 60000
         # �滨蔭�湧�憭帋��滩�銵䔶�甈⊥�瘚页�璉�瘚钅�閬���剔�蝛粹𤦭餈墧𦻖嚗��雿齿糓瘥怎�
         timeBetweenEvictionRunsMillis: 60000
@@ -80,10 +80,10 @@ spring:
         testWhileIdle: true
         testOnBorrow: false
         testOnReturn: false
-        # �枏�PSCache嚗�僎銝娍�摰𡁏�銝芾��乩�PSCache��之?
+        # �枏�PSCache嚗�僎銝娍�摰𡁏�銝芾��乩�PSCache��之嚙�?
         poolPreparedStatements: true
         maxPoolPreparedStatementPerConnectionSize: 20
-        # �滨蔭�烐綉蝏蠘恣�行⏛��ilters嚗�縧�匧��烐綉�屸𢒰sql�䭾�蝏蠘恣嚗?wall'�其��脩�憓?
+        # �滨蔭�烐綉蝏蠘恣�行⏛��ilters嚗�縧�匧��烐綉�屸𢒰sql�䭾�蝏蠘恣嚙�?wall'�其��脩�嚙�?
         filters: stat,wall,slf4j
         # �朞�connectProperties撅墧�扳䔉�枏�mergeSql�蠘�嚗𥟇�SQL霈啣�
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
@@ -127,7 +127,7 @@ spring:
 #mybatis plus 霈曄蔭
 mybatis-plus:
   mapper-locations: classpath*:/mapper/*Mapper.xml,classpath*:/mapper/*/*Mapper.xml
-  # 摰硺��急�嚗��銝?package �券�堒噡�𤥁����瑕��?
+  # 摰硺��急�嚗��嚙�?package �券�堒噡�𤥁����瑕�嚙�?
   type-aliases-package: com.storlead.tems.modules.*.entity
   type-enums-package:
     #  configuration:
@@ -138,9 +138,9 @@ mybatis-plus:
     # �喲𡡒MP3.0�芸蒂��anner
     banner: false
     db-config:
-      #銝駁睸蝐餃�  0:"�唳旿摨𨧻D�芸�",1:"霂亦掩�衤蛹�芾挽蝵桐蜓�桃掩�?, 2:"�冽�颲枏�ID",3:"�典��臭�ID (�啣�蝐餃��臭�ID)", 4:"�典��臭�ID UUID",5:"摮㛖泵銝脣�撅��臭�ID (idWorker ���蝚虫葡銵函內)";
+      #銝駁睸蝐餃�  0:"�唳旿摨𨧻D�芸�",1:"霂亦掩�衤蛹�芾挽蝵桐蜓�桃掩�?, 2:"�冽�颲枏�ID",3:"�典��臭�ID (�啣�蝐餃��臭�ID)", 4:"�典��臭�ID UUID",5:"摮㛖泵銝脣�撅��臭�ID (idWorker ���蝚虫葡銵函內)";
       id-type: 4
-      # 暺䁅恕�唳旿摨栞”銝见�蝥踹𦶢�?
+      # 暺䁅恕�唳旿摨栞”銝见�蝥踹𦶢�?
       table-underline: true
     #configuration:
     # 餈嗘葵�滨蔭隡𡁜��扯���ql�枏㫲�箸䔉嚗�銁撘��烐�瘚贝���𧒄�坔虾隞亦鍂
@@ -176,6 +176,7 @@ logging:
 environment: test
 dify:
   base-url: http://47.112.196.2:11434/v1/
+  download-url: http://47.112.196.2:11435
   dataset-api-key: dataset-qfhXMNcjsRSwN5CK6aoWx3hl
   app-keys:
     chat: app-1-qfhXMNcjsRSwN5CK6aoWx3hl  #撖寡�

+ 1 - 0
java/storlead-knowledge/storlead-knowledge-api/src/main/java/com/storlead/knowledge/api/DocumentController.java

@@ -154,6 +154,7 @@ public class DocumentController {
         String url = difyProperties.getBaseUrl() + "datasets/"+dataset_id + "/documents/"+ document_id+"/download";
         return httpService.get(
                 url,
+                difyProperties.getDownloadUrl(),
                 null,
                 "Bearer "+difyProperties.getDatasetApiKey(),
                 new TypeReference<>() {});

+ 1 - 0
java/storlead-knowledge/storlead-knowledge-core/src/main/java/com/storlead/knowledge/config/DifyProperties.java

@@ -14,6 +14,7 @@ import java.util.Map;
 public class DifyProperties {
 
     private String baseUrl;
+    private String downloadUrl;
     private String datasetApiKey;
     private Map<String, String> appKeys;
 

+ 45 - 1
java/storlead-knowledge/storlead-knowledge-core/src/main/java/com/storlead/knowledge/utils/HttpService.java

@@ -102,6 +102,50 @@ public class HttpService {
         }
     }
 
+    public <T> Result<T> get(
+            String url,
+            String downloadUrl,
+            Map<String, ?> queryParams,
+            String authorization,
+            TypeReference<T> typeReference
+    ) {
+        try {
+            String fullUrl = UrlBuilder.build(url, queryParams);
+            HttpRequest request = baseRequest(authorization)
+                    .uri(URI.create(fullUrl))
+                    .GET()
+                    .build();
+
+            HttpResponse<String> response =
+                    httpClient.send(request, HttpResponse.BodyHandlers.ofString());
+
+            return handleResponse(response,
+                    body -> {
+                        try {
+                            ObjectMapper mapper = new ObjectMapper();
+                            JsonNode rootNode = mapper.readTree(body);
+
+                            // 强制转为 ObjectNode 才能修改
+                            ObjectNode objectNode = (ObjectNode) rootNode;
+
+                            // 修改 url 的值
+                            String newUrl = downloadUrl + objectNode.get("url").asText();
+                            objectNode.put("url", newUrl);
+
+                            // 转回字符串
+                            String result = mapper.writeValueAsString(objectNode);
+
+                            return objectMapper.readValue(result, typeReference);
+                        } catch (JsonProcessingException e) {
+                            throw new RuntimeException(e);
+                        }
+                    });
+        } catch (Exception e) {
+            return (Result<T>) Result.error(e.getMessage());
+        }
+    }
+
+
     /* ================= POST ================= */
 
     public <T> Result<T> post(
@@ -363,7 +407,7 @@ public class HttpService {
 
         String CRLF = "\r\n";
         String prefix = "--" + boundary + CRLF;
-        String suffix = CRLF + "--" + boundary + "--";
+        String suffix = CRLF + "--" + boundary + "--";  
 
         ByteArrayOutputStream out = new ByteArrayOutputStream();