You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
4.0 KiB
129 lines
4.0 KiB
7 months ago
|
package Tools.MaxKb;
|
||
|
|
||
|
import Tools.MaxKb.Util.MaxKbDb;
|
||
|
import com.jfinal.kit.PropKit;
|
||
|
import com.jfinal.plugin.activerecord.Db;
|
||
|
import com.jfinal.plugin.activerecord.Record;
|
||
|
|
||
7 months ago
|
import java.time.LocalDateTime;
|
||
7 months ago
|
import java.util.UUID;
|
||
|
|
||
7 months ago
|
public class TestMaxKB {
|
||
7 months ago
|
|
||
|
/**
|
||
|
* 获取模型
|
||
|
*
|
||
|
* @param model_name 模型名称
|
||
|
* @return
|
||
|
*/
|
||
|
public static Record getModel(String model_name) {
|
||
|
String sql = "select * from model where name=?";
|
||
|
return Db.findFirst(sql, model_name);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取应用
|
||
|
*
|
||
|
* @param applicationName 应用名称
|
||
|
* @return
|
||
|
*/
|
||
|
public static Record getApplication(String applicationName) {
|
||
|
String sql = "select * from application where name=?";
|
||
|
return Db.findFirst(sql, applicationName);
|
||
|
}
|
||
|
|
||
7 months ago
|
/**
|
||
|
* 增加应用程序
|
||
7 months ago
|
*
|
||
7 months ago
|
* @param sourceApplicationName 源应用名称
|
||
|
* @param targetApplicationName 目标应用名称
|
||
|
*/
|
||
7 months ago
|
public static String addApplication(String sourceApplicationName, String targetApplicationName) {
|
||
7 months ago
|
//获取应用
|
||
|
Record record = getApplication(sourceApplicationName);
|
||
7 months ago
|
if (record == null) {
|
||
|
System.out.println(sourceApplicationName + "应用不存在!");
|
||
|
System.exit(0);
|
||
|
}
|
||
7 months ago
|
//克隆出对象
|
||
|
record = new Record().setColumns(record.getColumns());
|
||
|
//生成一个uuid
|
||
|
record.set("id", UUID.randomUUID());
|
||
|
//名称
|
||
|
record.set("name", targetApplicationName);
|
||
|
//增加
|
||
|
Db.save("application", "id", record);
|
||
7 months ago
|
|
||
|
return record.getStr("id");
|
||
7 months ago
|
}
|
||
|
|
||
7 months ago
|
/**
|
||
|
* 获取数据集
|
||
|
*
|
||
|
* @param dataset_name 数据集名称
|
||
|
* @return
|
||
|
*/
|
||
|
public static Record getDataSet(String dataset_name) {
|
||
|
String sql = "select * from dataset where name=?";
|
||
|
return Db.findFirst(sql, dataset_name);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 增加数据集
|
||
|
*
|
||
|
* @param sourceDatasetName 数据集名称
|
||
|
*/
|
||
7 months ago
|
public static String addDataSet(String sourceDatasetName, String targetDatasetName) {
|
||
7 months ago
|
//获取数据集
|
||
|
Record record = getDataSet(sourceDatasetName);
|
||
|
if (record == null) {
|
||
|
System.out.println(sourceDatasetName + "数据集不存在!");
|
||
|
System.exit(0);
|
||
|
}
|
||
|
//克隆出对象
|
||
|
record = new Record().setColumns(record.getColumns());
|
||
|
//生成一个uuid
|
||
|
record.set("id", UUID.randomUUID());
|
||
|
//名称
|
||
|
record.set("name", targetDatasetName);
|
||
|
record.set("desc", targetDatasetName);
|
||
|
//增加
|
||
|
Db.save("dataset", "id", record);
|
||
7 months ago
|
return record.getStr("id");
|
||
7 months ago
|
}
|
||
|
|
||
|
|
||
7 months ago
|
public static void main(String[] args) throws Exception {
|
||
|
//加载配置文件
|
||
|
PropKit.use("MaxKb.properties");
|
||
|
//初始化数据库
|
||
|
MaxKbDb.Init();
|
||
|
|
||
|
//获取模型的id
|
||
|
String model_name = "DeepSeek";
|
||
|
Record record = getModel(model_name);
|
||
|
String model_id = record.getStr("id");
|
||
|
System.out.println(model_id);
|
||
|
|
||
7 months ago
|
//拷贝生成应用
|
||
|
String sourceApplicationName = "应用【模板】";
|
||
|
String targetApplicationName = "XXX的应用";
|
||
|
String application_id = addApplication(sourceApplicationName, targetApplicationName);
|
||
|
|
||
|
//拷贝生成知识库
|
||
|
String sourceDataSetName = "知识库【模板】";
|
||
|
String targetDataSetName = "XXX的知识库";
|
||
|
String dataset_id = addDataSet(sourceDataSetName, targetDataSetName);
|
||
7 months ago
|
|
||
7 months ago
|
//应用与知识库关联
|
||
|
record = new Record();
|
||
|
record.set("create_time", LocalDateTime.now());
|
||
|
record.set("update_time", LocalDateTime.now());
|
||
|
record.set("id", UUID.randomUUID());
|
||
|
record.set("application_id", UUID.fromString(application_id));
|
||
|
record.set("dataset_id", UUID.fromString(dataset_id));
|
||
|
Db.save("application_dataset_mapping", "id", record);
|
||
|
|
||
|
System.out.println("增加成功!");
|
||
7 months ago
|
}
|
||
|
}
|