main
黄海 7 months ago
parent 1f05f04443
commit 0ab2adb36f

@ -28,19 +28,31 @@ public class MaxKbModel {
/**
*
*
* @param documentId id
*/
public void delDocumentProblem(String documentId) {
//根据文档id查找它相关有哪些问题id,并且删除问题
String sql = "select * from problem_paragraph_mapping where document_id=?";
String sql = "select * from problem_paragraph_mapping where document_id=?::uuid";
List<Record> recordList = Db.find(sql, documentId);
for (Record record : recordList) {
String problem_id = record.getStr("problem_id");
sql = "delete from problem where id=?";
sql = "delete from problem where id=?::uuid";
Db.update(sql, problem_id);
}
//相关的都删除掉了,需要删除问题与段落的关联关系了
sql = "delete from problem_paragraph_mapping where document_id=?";
sql = "delete from problem_paragraph_mapping where document_id=?::uuid";
Db.update(sql, documentId);
}
/**
*
*
* @param modelName
* @return
*/
public List<Record> getModel(String modelName) {
String sql = "select * from model where name=?";
return Db.find(sql, modelName);
}
}

@ -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());
}
}

@ -52,6 +52,22 @@ public class MaxKbService {
//1、需要找出根据此文档有哪些已经生成的问题并且需要删除掉所有已经生成的问题
mm.delDocumentProblem(documentId);
//2、需要重新生成问题
//TODO
String modelName = PropKit.get("modelName");
String model_id = getModelIdByModelName(modelName);
//生成问题
MaxKbImpl.generateQuestion(authCode, zskId, model_id, documentId);
}
/**
* ID
*
* @param modelName
* @return
*/
public static String getModelIdByModelName(String modelName) {
List<Record> list = mm.getModel(modelName);
if (list.isEmpty()) return null;
return list.getFirst().getStr("id");
}
}

@ -9,4 +9,7 @@ baseUrl=http://10.10.14.206:8080
MaxKBUsername=admin
MaxKBPassword=Dsideal4r5t6y7u!@#
# 知识库的名称【知识库的名称是固定的,变化的应该是知识库里面的文档】
dataSetName=测试用的知识库
dataSetName=测试用的知识库
# 大语言模型名称【通义千问qwen-max】
modelName=我的模型
Loading…
Cancel
Save