| | |
| | | getAgentIntention,
|
| | | getAgentLayerList,
|
| | | getAgentThistorySave,
|
| | | getRagAgentIntention,
|
| | | } from "../../api/api.js";
|
| | | import mapSetFunc from "../../assets/js/mapSetFunc.js";
|
| | | import { nanoid } from "nanoid";
|
| | | import mapServer from "../../assets/js/map/mapServer.js";
|
| | | import mapImg from "../../assets/js/map/mapImg.js";
|
| | | import mapModel from "../../assets/js/map/mapModel.js";
|
| | | import { marked } from "marked";
|
| | | export default {
|
| | | name: "jwChat",
|
| | |
|
| | |
| | | // 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(),
|
| | | };
|
| | |
|
| | | var obj = {
|
| | | ai: "",
|
| | | create_time: msgData.getDate1(),
|
| | | human: res,
|
| | | sessionid: this.uuid,
|
| | | update_time: "",
|
| | | userid: 0,
|
| | | };
|
| | | if (formData.message.indexOf("@map") > -1) {
|
| | | var obj = {
|
| | | ai: "",
|
| | | create_time: msgData.getDate1(),
|
| | | human: res,
|
| | | sessionid: this.uuid,
|
| | | update_time: "",
|
| | | userid: 0,
|
| | | };
|
| | | getAgentThistorySave(obj).then((response) => {
|
| | | if (response.code == 200) {
|
| | | obj.id = response.id;
|
| | | this.obj = obj;
|
| | | }
|
| | | this.setAgentIntention(obj, formData);
|
| | | });
|
| | | } else {
|
| | | this.setRagAgentIntention(formData);
|
| | | }
|
| | |
|
| | | getAgentThistorySave(obj).then((response) => {
|
| | | if (response.code == 200) {
|
| | | obj.id = response.id;
|
| | | this.obj = obj;
|
| | | }
|
| | |
|
| | | this.setAgentIntention(obj, formData);
|
| | | });
|
| | | // var obj = {
|
| | | // ai: "",
|
| | | // create_time: msgData.getDate1(),
|
| | | // human: res,
|
| | | // sessionid: this.uuid,
|
| | | // update_time: "",
|
| | | // userid: 0,
|
| | | // };
|
| | | // getAgentThistorySave(obj).then((response) => {
|
| | | // if (response.code == 200) {
|
| | | // obj.id = response.id;
|
| | | // this.obj = obj;
|
| | | // }
|
| | | // this.setAgentIntention(obj, formData);
|
| | | // });
|
| | | },
|
| | | //地图相关问答
|
| | | async setAgentIntention(obj, formData) {
|
| | | console.log("obj", formData);
|
| | | getAgentIntention(formData)
|
| | | .then((response) => {
|
| | | if (response.code != 200) {
|
| | | if (formData.message != "@map") {
|
| | | if (formData.message.indexOf("@map") > -1) {
|
| | | getAgentIntention(formData)
|
| | | .then((response) => {
|
| | | if (response.code != 200) {
|
| | | if (formData.message != "@map") {
|
| | | var rolMsg = [
|
| | | {
|
| | | type: "text",
|
| | | val: "未查询到相关信息。",
|
| | | },
|
| | | ];
|
| | | this.refashMsg(rolMsg);
|
| | | }
|
| | | return;
|
| | | }
|
| | | const type = response.type;
|
| | | //普通对话信息查询
|
| | | if (type == "message" || type == "Rag") {
|
| | | //关闭地图
|
| | | if (!this.closeMap) {
|
| | | this.$store.state.setScreenFlag = false;
|
| | | }
|
| | | var rolMsg = [
|
| | | {
|
| | | type: "text",
|
| | | val: "未查询到相关信息。",
|
| | | val: type == "Rag" ? response.content : response.msg,
|
| | | },
|
| | | ];
|
| | | this.refashMsg(rolMsg);
|
| | | }
|
| | | return;
|
| | | }
|
| | |
|
| | | const type = response.type;
|
| | | //普通对话信息查询
|
| | | if (type == "message" || type == "Rag") {
|
| | | //关闭地图
|
| | | if (!this.closeMap) {
|
| | | this.$store.state.setScreenFlag = false;
|
| | | //地图查询
|
| | | else {
|
| | | //打开地图
|
| | | this.$store.state.setScreenFlag = true;
|
| | | this.setMapfunc(response.content, obj);
|
| | | }
|
| | | })
|
| | | .catch((error) => {
|
| | | var rolMsg = [
|
| | | {
|
| | | type: "text",
|
| | | val: type == "Rag" ? response.content : response.msg,
|
| | | val: "未查询到相关信息。",
|
| | | },
|
| | | ];
|
| | | this.refashMsg(rolMsg);
|
| | | });
|
| | | } else {
|
| | | getRagAgentIntention(formData).then((res) => {});
|
| | | }
|
| | | // getAgentIntention(formData)
|
| | | // .then((response) => {
|
| | | // if (response.code != 200) {
|
| | | // if (formData.message != "@map") {
|
| | | // var rolMsg = [
|
| | | // {
|
| | | // type: "text",
|
| | | // val: "未查询到相关信息。",
|
| | | // },
|
| | | // ];
|
| | | // this.refashMsg(rolMsg);
|
| | | // }
|
| | | // return;
|
| | | // }
|
| | | // const type = response.type;
|
| | | // //普通对话信息查询
|
| | | // if (type == "message" || type == "Rag") {
|
| | | // //关闭地图
|
| | | // if (!this.closeMap) {
|
| | | // this.$store.state.setScreenFlag = false;
|
| | | // }
|
| | | // var rolMsg = [
|
| | | // {
|
| | | // type: "text",
|
| | | // val: type == "Rag" ? response.content : response.msg,
|
| | | // },
|
| | | // ];
|
| | | // this.refashMsg(rolMsg);
|
| | | // }
|
| | | // //地图查询
|
| | | // else {
|
| | | // //打开地图
|
| | | // this.$store.state.setScreenFlag = true;
|
| | | // this.setMapfunc(response.content, obj);
|
| | | // }
|
| | | // })
|
| | | // .catch((error) => {
|
| | | // var rolMsg = [
|
| | | // {
|
| | | // type: "text",
|
| | | // val: "抱歉,服务器似乎出了点问题,我们正在修复中。",
|
| | | // },
|
| | | // ];
|
| | | // this.refashMsg(rolMsg);
|
| | | // });
|
| | | },
|
| | | //普通对话问答
|
| | | async setRagAgentIntention(formData) {
|
| | | try {
|
| | | // 发送请求
|
| | | const params = new URLSearchParams(formData);
|
| | | const url = `/rag-api/rag?${params.toString()}`;
|
| | | let response = await fetch(url, {
|
| | | method: "get",
|
| | | responseType: "stream",
|
| | | headers: {
|
| | | "Content-Type": "application/json",
|
| | | },
|
| | | });
|
| | | // ok字段判断是否成功获取到数据流
|
| | | if (!response.ok) {
|
| | | var rolMsg = [
|
| | | {
|
| | | type: "text",
|
| | | val: "未查询到相关信息。",
|
| | | },
|
| | | ];
|
| | | this.refashMsg(rolMsg);
|
| | | return;
|
| | | }
|
| | | // 用来获取一个可读的流的读取器(Reader)以流的方式处理响应体数据
|
| | | const reader = response.body.getReader();
|
| | | // 将流中的字节数据解码为文本字符串
|
| | | const textDecoder = new TextDecoder();
|
| | | let result = true;
|
| | | let sendMsg = true;
|
| | | let sqlValue = "";
|
| | | while (result) {
|
| | | // done表示流是否已经完成读取 value包含读取到的数据块
|
| | | const { done, value } = await reader.read();
|
| | | if (done) {
|
| | | result = false;
|
| | | break;
|
| | | }
|
| | | 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);
|
| | | }
|
| | | //地图查询
|
| | | else {
|
| | | //打开地图
|
| | | this.$store.state.setScreenFlag = true;
|
| | | this.setMapfunc(response.content, obj);
|
| | | }
|
| | | })
|
| | | .catch((error) => {
|
| | | var rolMsg = [
|
| | | {
|
| | | type: "text",
|
| | | val: "抱歉,服务器似乎出了点问题,我们正在修复中。",
|
| | | },
|
| | | ];
|
| | | this.refashMsg(rolMsg);
|
| | | });
|
| | | }
|
| | | // console.log(sqlValue, "输出所有返回数据");
|
| | | } catch (err) {
|
| | | var rolMsg = [
|
| | | {
|
| | | type: "text",
|
| | | val: "未查询到相关信息。",
|
| | | },
|
| | | ];
|
| | | this.refashMsg(rolMsg);
|
| | | }
|
| | | },
|
| | | setMapfunc(res, obj) {
|
| | | this.$store.state.showLenged = false;
|