|
|
|
@ -5,15 +5,19 @@ 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;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class MaxKbImpl {
|
|
|
|
|
//MaxKB的url
|
|
|
|
|
static final String baseUrl = PropKit.get("baseUrl");
|
|
|
|
|
//获取身份识别码接口
|
|
|
|
|
static final String Authorization_URL = baseUrl + "/api/user/login";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 上传QA文件到知识库
|
|
|
|
|
*
|
|
|
|
@ -113,4 +117,33 @@ public class MaxKbImpl {
|
|
|
|
|
.execute();
|
|
|
|
|
return com.alibaba.fastjson.JSONObject.parseObject(response.body());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成问题
|
|
|
|
|
* @param authCode 身份识别码
|
|
|
|
|
* @param zskId 知识库id
|
|
|
|
|
* @param modelId 模型id
|
|
|
|
|
* @param documentId 文档id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static com.alibaba.fastjson.JSONObject generateQuestion(String authCode, String zskId, String modelId, String documentId) {
|
|
|
|
|
String url = baseUrl + "/api/dataset/" + zskId + "/document/batch_generate_related";
|
|
|
|
|
com.alibaba.fastjson.JSONObject jo = new com.alibaba.fastjson.JSONObject();
|
|
|
|
|
jo.put("model_id", modelId);
|
|
|
|
|
jo.put("prompt", "内容:{data}\\n\\n请总结上面的内容,并根据内容总结生成 5 个问题。\\n回答要求:\\n- 请只输出问题;\\n- 请将每个问题放置<question></question>标签中。");
|
|
|
|
|
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")
|
|
|
|
|
.header("Accept-Language", "zh-CN,zh;q=0.9")
|
|
|
|
|
.header("Authorization", authCode)// 添加header
|
|
|
|
|
.header("Connection", "keep-alive")
|
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
|
.body(jo.toJSONString()).execute();
|
|
|
|
|
return com.alibaba.fastjson.JSONObject.parseObject(response.body());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|