main
黄海 7 months ago
parent 5c71283bce
commit 20cd63d324

@ -153,13 +153,13 @@ public class MaxKbImpl {
/**
*
*
* @param authCode
* @param zskId id
* @param modelId id
* @param documentId id
* @return
*/
public static JSONObject generateQuestion(String authCode, String zskId, String modelId, String documentId) {
public static JSONObject generateQuestion(String zskId, String modelId, String documentId) {
String authCode=MaxKbImpl.getAuthorization();
String url = baseUrl + "/api/dataset/" + zskId + "/document/batch_generate_related";
JSONObject jo = new JSONObject();
jo.put("model_id", modelId);

@ -14,31 +14,41 @@ public class MaxKbService {
public static MaxKbModel mm = new MaxKbModel();
/**
*
* ID
*
* @param dataSetName
* @param uploadFile
* @param zskName
* @return
*/
public static void uploadQA(String dataSetName, String uploadFile) {
List<Record> list = mm.getDataSetList(dataSetName);
public static String getZskId(String zskName) {
List<Record> list = mm.getDataSetList(zskName);
if (list.size() > 1) {
System.out.println("数据集:【" + dataSetName + "】名称重复,请检查后重新运行!");
return;
System.out.println("数据集:【" + zskName + "】名称重复,请检查后重新运行!");
return null;
}
if (list.isEmpty()) {
System.out.println("数据集:【" + dataSetName + "】不存在,请检查后重新运行!");
return;
System.out.println("数据集:【" + zskName + "】不存在,请检查后重新运行!");
return null;
}
//数据集ID
String zskId = list.getFirst().getStr("id");
return list.getFirst().getStr("id");
}
/**
*
*
* @param zskName
* @param uploadFile
*/
public static String uploadQA(String zskName, String uploadFile) {
//数据集ID
String zskId = getZskId(zskName);
//在上传文档前,需要删除掉旧的同名文档
File fi = new File(uploadFile);
String fileName = fi.getName();
//获取身份识别
String authCode = MaxKbImpl.getAuthorization();
//上传文档
List<com.jfinal.plugin.activerecord.Record> listDocuments = mm.getDocumentListByDataSetId(zskId);
List<Record> listDocuments = mm.getDocumentListByDataSetId(zskId);
for (Record record : listDocuments) {
String documentName = record.getStr("name");
if (documentName.equals(fileName)) {
@ -51,12 +61,7 @@ public class MaxKbService {
}
}
//上传新的文档
String documentId = MaxKbImpl.uploadQA(authCode, zskId, uploadFile);
//2、需要重新生成问题
String modelName = PropKit.get("modelName");
String model_id = getModelIdByModelName(modelName);
//生成问题
MaxKbImpl.generateQuestion(authCode, zskId, model_id, documentId);
return MaxKbImpl.uploadQA(authCode, zskId, uploadFile);
}
@ -85,19 +90,9 @@ public class MaxKbService {
/**
*
*/
public static String _bach(String dataSetName, String uploadFile) {
List<Record> list = mm.getDataSetList(dataSetName);
if (list.size() > 1) {
System.out.println("数据集:【" + dataSetName + "】名称重复,请检查后重新运行!");
return null;
}
if (list.isEmpty()) {
System.out.println("数据集:【" + dataSetName + "】不存在,请检查后重新运行!");
return null;
}
public static String _bach(String zskName, String uploadFile) {
//数据集ID
String zskId = list.getFirst().getStr("id");
String zskId = getZskId(zskName);
//上传文件
JSONObject jo = splitDocument(uploadFile);
JSONArray ja = jo.getJSONArray("data");
@ -113,22 +108,13 @@ public class MaxKbService {
/**
*
* @param dataSetName
* @param documentId id
*
* @param documentId id
* @return
*/
public static String batch_generate_related(String dataSetName, String documentId) {
List<Record> list = mm.getDataSetList(dataSetName);
if (list.size() > 1) {
System.out.println("数据集:【" + dataSetName + "】名称重复,请检查后重新运行!");
return null;
}
if (list.isEmpty()) {
System.out.println("数据集:【" + dataSetName + "】不存在,请检查后重新运行!");
return null;
}
public static String batch_generate_related(String zskName, String documentId) {
//数据集ID
String zskId = list.getFirst().getStr("id");
String zskId = getZskId(zskName);
return MaxKbImpl.batch_generate_related(MaxKbImpl.getAuthorization(), zskId, documentId);
}
}

@ -1,12 +1,13 @@
package Tools.MaxKb;
import Tools.MaxKb.Service.Impl.MaxKbImpl;
import Tools.MaxKb.Service.MaxKbService;
import Tools.MaxKb.Util.MaxKbUtil;
import com.jfinal.kit.PropKit;
public class UploadQA {
//要上传的QA知识内容
static String uploadFile = "D:\\dsWork\\QingLong\\Doc\\MaxKB\\各学校人员和班级统计【结果】.xlsx";
static String uploadFile = "D:\\dsWork\\QingLong\\Doc\\MaxKB\\黄海的个人简历【QA版本】.xlsx";
public static void main(String[] args) throws Exception {
//加载配置文件
@ -14,9 +15,14 @@ public class UploadQA {
//初始化数据库
MaxKbUtil.Init();
//上传文件
//获取数据集名称
String dataSetName = "应用【模板】";
MaxKbService.uploadQA(dataSetName,uploadFile);
String zskName = "知识库【模板】";
String documentId = MaxKbService.uploadQA(zskName, uploadFile);
//2、需要重新生成问题
String modelName = PropKit.get("modelName");
String model_id = MaxKbService.getModelIdByModelName(modelName);
//生成问题
MaxKbImpl.generateQuestion(zskName, model_id, documentId);
System.out.println("恭喜,所有操作成功完成!");
}
}
Loading…
Cancel
Save