|
|
|
@ -1,11 +1,11 @@
|
|
|
|
|
package Tools.MaxKb.Service.Impl;
|
|
|
|
|
|
|
|
|
|
import Tools.MaxKb.Util.MaxKbUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
@ -48,6 +48,37 @@ public class MaxKbImpl {
|
|
|
|
|
return jo.getJSONArray("data").getJSONObject(0).getStr("id");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 上传文档并分段
|
|
|
|
|
*
|
|
|
|
|
* @param authCode 验证码
|
|
|
|
|
* @param uploadFile 上传的文件
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static JSONObject uploadDocumentSplit(String authCode, String uploadFile) {
|
|
|
|
|
//知识库url上传地址
|
|
|
|
|
String qaUrl = baseUrl + "/api/dataset/document/split";
|
|
|
|
|
//使用hutool工具箱里面的httpPost功能,向指定的接口发起上传文件的请求,在Header中携带参数authCode
|
|
|
|
|
HttpResponse response = HttpRequest.post(qaUrl)
|
|
|
|
|
.header("Accept", "application/json, text/plain, */*")
|
|
|
|
|
.header("Accept-Encoding", "gzip,deflate")
|
|
|
|
|
.header("Accept-Language", "zh-CN,zh;q=0.9")
|
|
|
|
|
.header("Authorization", authCode)// 添加header
|
|
|
|
|
.header("Connection", "keep-alive")
|
|
|
|
|
.header("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundaryhEiEDpZDka6byweA")
|
|
|
|
|
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36")
|
|
|
|
|
.form("file", new File(uploadFile)).execute();// 添加文件
|
|
|
|
|
// 获取响应内容
|
|
|
|
|
String result = response.body();
|
|
|
|
|
JSONObject jo = JSONUtil.parseObj(result);
|
|
|
|
|
int code = jo.getInt("code");
|
|
|
|
|
if (code != 200) {
|
|
|
|
|
System.out.println("请求失败");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return jo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 发送请求获取识别码
|
|
|
|
@ -120,9 +151,10 @@ public class MaxKbImpl {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成问题
|
|
|
|
|
* @param authCode 身份识别码
|
|
|
|
|
* @param zskId 知识库id
|
|
|
|
|
* @param modelId 模型id
|
|
|
|
|
*
|
|
|
|
|
* @param authCode 身份识别码
|
|
|
|
|
* @param zskId 知识库id
|
|
|
|
|
* @param modelId 模型id
|
|
|
|
|
* @param documentId 文档id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -134,7 +166,6 @@ public class MaxKbImpl {
|
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
|
list.add(documentId);
|
|
|
|
|
jo.put("document_id_list", list);
|
|
|
|
|
//使用Hutool的PUT调用接口
|
|
|
|
|
HttpResponse response = HttpRequest.put(url)
|
|
|
|
|
.header("Accept", "application/json, text/plain, */*")
|
|
|
|
|
.header("Accept-Encoding", "gzip,deflate")
|
|
|
|
@ -146,4 +177,17 @@ public class MaxKbImpl {
|
|
|
|
|
return com.alibaba.fastjson.JSONObject.parseObject(response.body());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String _bach(String authCode, String zskId, String body) {
|
|
|
|
|
String url = baseUrl + "/api/dataset/" + zskId + "/document/_bach";
|
|
|
|
|
HttpResponse response = HttpRequest.put(url)
|
|
|
|
|
.header("Accept", "application/json, text/plain, */*")
|
|
|
|
|
.header("Accept-Encoding", "gzip,deflate")
|
|
|
|
|
.header("Accept-Language", "zh-CN,zh;q=0.9")
|
|
|
|
|
.header("Authorization", authCode)// 添加header
|
|
|
|
|
.header("Connection", "keep-alive")
|
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
|
.body(body).execute();
|
|
|
|
|
return response.body();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|