| | |
| | | // formData.append("lib_id", "No1");
|
| | | // formData.append("session_id", this.uuid.toString());
|
| | | const formData = {
|
| | | message: res,
|
| | | message: res.replace(/\s+/g, ""),
|
| | | lib_id: "No1",
|
| | | session_id: this.uuid.toString(),
|
| | | };
|
| | |
| | | // this.setAgentIntention(obj, formData);
|
| | | // });
|
| | | },
|
| | | //地图相关问答
|
| | | async setAgentIntention(obj, formData) {
|
| | | console.log("obj", formData);
|
| | | if (formData.message.indexOf("@map") > -1) {
|
| | |
| | | // 将流中的字节数据解码为文本字符串
|
| | | const textDecoder = new TextDecoder();
|
| | | let result = true;
|
| | | let sendMsg = true;
|
| | | let sqlValue = "";
|
| | | while (result) {
|
| | | // done表示流是否已经完成读取 value包含读取到的数据块
|
| | |
| | | result = false;
|
| | | break;
|
| | | }
|
| | | console.log(textDecoder.decode(value), "分段返回的数据");
|
| | | sqlValue += textDecoder.decode(value);
|
| | | var rolMsg = [
|
| | | {
|
| | | type: "stream",
|
| | | val: marked(sqlValue),
|
| | | },
|
| | | ];
|
| | | this.refashMsg(rolMsg);
|
| | | let resText = textDecoder.decode(value);
|
| | | //包含<think>停止输出
|
| | | //包含</think>继续输出
|
| | | console.log(resText, "返回的数据");
|
| | | if (resText.indexOf("<think>") > -1) {
|
| | | sendMsg = false;
|
| | | }
|
| | | if (resText.indexOf("</think>") > -1) {
|
| | | sendMsg = true;
|
| | | let position = resText.indexOf('</think>');
|
| | | resText = resText.substring(position + "</think>".length);
|
| | | }
|
| | | if (sendMsg) {
|
| | | sqlValue += resText;
|
| | | var rolMsg = [
|
| | | {
|
| | | type: "stream",
|
| | | val: marked(sqlValue),
|
| | | },
|
| | | ];
|
| | | this.refashMsg(rolMsg);
|
| | | }
|
| | | }
|
| | | // console.log(sqlValue, "输出所有返回数据");
|
| | | } catch (err) {
|
| | | var rolMsg = [
|
| | | {
|
| | | type: "text",
|
| | | val: "未查询到相关信息。",
|
| | | },
|
| | | ];
|
| | | this.refashMsg(rolMsg);
|
| | | }
|
| | | },
|
| | | async streamChatResponse(formData) {
|
| | | try {
|
| | | const response = await getRagAgentIntention(formData);
|
| | | return response; // 返回流响应
|
| | | } catch (error) {
|
| | | var rolMsg = [
|
| | | {
|
| | | type: "text",
|
| | |
| | | }, |
| | | }, |
| | | }); |
| | | earthCtrl.camera.flyTo(entity.lontitude, entity.lattitude, 3000, 0, -90, 0, 2); |
| | | earthCtrl.camera.flyTo(entity.lontitude, entity.lattitude, 1000, 0, -90, 0, 2); |
| | | }, |
| | | }, |
| | | |