|
|
|
@ -1,40 +1,28 @@
|
|
|
|
|
package UnitTest;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import Tools.MaxKb.Model.MaxKbModel;
|
|
|
|
|
import Tools.MaxKb.Service.Impl.MaxKbImpl;
|
|
|
|
|
import Tools.MaxKb.Util.MaxKbUtil;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
|
|
|
|
|
public class TestMaxKB {
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
String apiKey = "application-490cc01132c6f752e37d1570f562aa6c";
|
|
|
|
|
String applicationId = "999bf92e-c659-11ef-9f22-0242ac120003";
|
|
|
|
|
String filePath = "D:\\dsWork\\QingLong\\Doc\\MaxKB\\黄海的个人简历.txt";
|
|
|
|
|
MaxKbModel mkm = new MaxKbModel();
|
|
|
|
|
//加载配置文件
|
|
|
|
|
PropKit.use("MaxKb.properties");
|
|
|
|
|
//初始化数据库
|
|
|
|
|
//MaxKbUtil.Init();
|
|
|
|
|
|
|
|
|
|
//根据应用id,获取会话id
|
|
|
|
|
String url = "http://10.10.14.206:8080/api/application/" + applicationId + "/chat/open";
|
|
|
|
|
String result = HttpRequest.get(url)
|
|
|
|
|
.header("Authorization", apiKey)
|
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
|
.execute()
|
|
|
|
|
.body();
|
|
|
|
|
String apiKey = "application-83bfbc8a53b567a6d0e300680689655c";
|
|
|
|
|
String applicationId = "ddea9cf9-fe45-4c4a-af67-cf095e3acd05";
|
|
|
|
|
|
|
|
|
|
String chat_id = JSONObject.parseObject(result).getString("data");
|
|
|
|
|
//String chat_id = MaxKbImpl.getChatId(apiKey, applicationId);
|
|
|
|
|
//System.out.println(chat_id);
|
|
|
|
|
|
|
|
|
|
System.out.println(chat_id);
|
|
|
|
|
|
|
|
|
|
//对话
|
|
|
|
|
url = "http://10.10.14.206:8080/api/application/chat_message/" + chat_id;
|
|
|
|
|
JSONObject jo = new JSONObject();
|
|
|
|
|
jo.put("message", "你好!我的名字叫黄海,记住我!一会我会问你我叫什么名字!");
|
|
|
|
|
//jo.put("message", "你好!你知道我叫什么名字吗?");
|
|
|
|
|
jo.put("stream", true);
|
|
|
|
|
jo.put("re_chat", false);
|
|
|
|
|
result = HttpRequest.post(url)
|
|
|
|
|
.header("Authorization", apiKey)
|
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
|
.body(jo.toString())
|
|
|
|
|
.execute()
|
|
|
|
|
.body();
|
|
|
|
|
|
|
|
|
|
System.out.println(result);
|
|
|
|
|
String chat_id="33341d50-c718-11ef-a24e-0242ac120003";
|
|
|
|
|
MaxKbImpl.sendChatMessage(apiKey, chat_id, FileUtil.readUtf8String(filePath));
|
|
|
|
|
|
|
|
|
|
// for (String s : result.split("\n")) {
|
|
|
|
|
// //JSONObject jsonObject= JSONObject.parseObject(s);
|
|
|
|
|