yxl
2025-02-10 ee07b9f5e0ca5344bf5b78fcf87355d065d8c2b7
src/views/chartView/index.vue
@@ -257,7 +257,7 @@
      // 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(),
      };
@@ -298,6 +298,7 @@
      //   this.setAgentIntention(obj, formData);
      // });
    },
    //地图相关问答
    async setAgentIntention(obj, formData) {
      console.log("obj", formData);
      if (formData.message.indexOf("@map") > -1) {
@@ -424,6 +425,7 @@
        // 将流中的字节数据解码为文本字符串
        const textDecoder = new TextDecoder();
        let result = true;
        let sendMsg = true;
        let sqlValue = "";
        while (result) {
          // done表示流是否已经完成读取  value包含读取到的数据块
@@ -432,32 +434,31 @@
            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",