yxl
2025-02-17 ce6022e709c4b329785a624381fd51ad41371209
src/views/chartView/index.vue
@@ -149,7 +149,7 @@
      const item = {
        sourceType: "Tileset",
        name: "MilitaryFacilities",
        url: "/data-api/gisserver/c3dserver/sedb_DESKTOP-15DOTHJ_SEM4550/tileset.json",
        url: config.modelUrl,
      };
      setTimeout(() => {
        mapServer.addServer(item);
@@ -257,30 +257,30 @@
      // 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(),
      };
      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;
          }
      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;
        }
        if (formData.message.indexOf("@map") > -1) {
          this.setAgentIntention(obj, formData);
        });
      } else {
        this.setRagAgentIntention(formData);
      }
        } else {
          this.setRagAgentIntention(obj, formData);
        }
      });
      // var obj = {
      //   ai: "",
@@ -298,6 +298,7 @@
      //   this.setAgentIntention(obj, formData);
      // });
    },
    //地图相关问答
    async setAgentIntention(obj, formData) {
      console.log("obj", formData);
      if (formData.message.indexOf("@map") > -1) {
@@ -396,7 +397,7 @@
      //   });
    },
    //普通对话问答
    async setRagAgentIntention(formData) {
    async setRagAgentIntention(obj, formData) {
      try {
        // 发送请求
        const params = new URLSearchParams(formData);
@@ -424,40 +425,42 @@
        // 将流中的字节数据解码为文本字符串
        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;
            this.setUpdateHistoryInFor(obj, sqlValue);
            console.log(sqlValue, "sqlValue-----");
            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",
@@ -636,6 +639,18 @@
          this.setUpdateHistoryInFor(obj, res.msg);
          this.refashMsg(roleMsg.list);
          break;
        case "getTAIWAN":
          mapSetFunc.init(res);
          console.log("res.data.targetinfo", res);
          const resInfo = res.data
            .map((item) => `| ${item.name} | ${item.targetinfo} |`)
            .join("\n");
          var attr = `| 名称 | 属性信息 |\n|------|------|\n` + resInfo;
          console.log("aaa", attr);
          var roleMsg = msgData.getMdData("markdown", attr);
          this.setUpdateHistoryInFor(obj, res.msg);
          this.refashMsg(roleMsg.list);
          break;
        case "attackentity":
          mapSetFunc.init(res);
          this.setUpdateHistoryInFor(obj, res.msg);