From 3dc17dbcb1fb1d64c469deed1518d1817846b452 Mon Sep 17 00:00:00 2001 From: yxl <584911253@qq.com> Date: 星期三, 19 二月 2025 09:49:50 +0800 Subject: [PATCH] commit --- src/views/chartView/index.vue | 269 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 227 insertions(+), 42 deletions(-) diff --git a/src/views/chartView/index.vue b/src/views/chartView/index.vue index 5d12549..f4f4ec2 100644 --- a/src/views/chartView/index.vue +++ b/src/views/chartView/index.vue @@ -22,12 +22,14 @@ 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", @@ -106,12 +108,6 @@ this.setRagMoreList(res); } }); - // axios.get("http://192.168.11.89:12315/Markdown.md").then((response) => { - // if (response.status == 200) { - // console.log(response); - // this.setMarkDownInfo(response.data); - // } - // }); }, methods: { createSocket() { @@ -147,7 +143,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); @@ -249,13 +245,8 @@ this.$store.state.setListColor = []; this.$store.state.showLenged = false; this.$store.state.showRelationBox = false; - - // const formData = new FormData(); - // formData.append("message", res); - // 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(), }; @@ -268,65 +259,247 @@ update_time: "", userid: 0, }; - getAgentThistorySave(obj).then((response) => { if (response.code == 200) { obj.id = response.id; this.obj = obj; } - - this.setAgentIntention(obj, formData); + if (formData.message.indexOf("@map") > -1) { + this.setAgentIntention(obj, formData); + } else { + this.setRagAgentIntention(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 { - //鎵撳紑鍦板浘 - this.$store.state.setScreenFlag = true; - this.setMapfunc(response.content, obj); - } - }) - .catch((error) => { + }); + } 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: "鎶辨瓑锛屾湇鍔″櫒浼间箮鍑轰簡鐐归棶棰橈紝鎴戜滑姝e湪淇涓��", + // }, + // ]; + // this.refashMsg(rolMsg); + // }); + }, + //鏅�氬璇濋棶绛� + async setRagAgentIntention(obj, 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: "鎶辨瓑锛屾湇鍔″櫒浼间箮鍑轰簡鐐归棶棰橈紝鎴戜滑姝e湪淇涓��", + val: "鏈煡璇㈠埌鐩稿叧淇℃伅銆�", }, ]; this.refashMsg(rolMsg); - }); + return; + } + // 鐢ㄦ潵鑾峰彇涓�涓彲璇荤殑娴佺殑璇诲彇鍣紙Reader锛変互娴佺殑鏂瑰紡澶勭悊鍝嶅簲浣撴暟鎹� + const reader = response.body.getReader(); + // 灏嗘祦涓殑瀛楄妭鏁版嵁瑙g爜涓烘枃鏈瓧绗︿覆 + const textDecoder = new TextDecoder(); + let result = true; + let thinkMsg = false; + let sqlValue = ""; + let afterText = ""; + while (result) { + // done琛ㄧず娴佹槸鍚﹀凡缁忓畬鎴愯鍙� value鍖呭惈璇诲彇鍒扮殑鏁版嵁鍧� + const { done, value } = await reader.read(); + if (done) { + result = false; + this.setUpdateHistoryInFor(obj, sqlValue); + console.log(sqlValue, "sqlValue-----"); + break; + } + let resText = textDecoder.decode(value); + //鍖呭惈<think>鍋滄杈撳嚭 + //鍖呭惈</think>缁х画杈撳嚭 + console.log(resText, "杩斿洖鐨勬暟鎹�"); + if (resText.indexOf("<think>") > -1) { + resText = resText.replace(/<think>/, ""); + thinkMsg = true; + sqlValue += resText; + var rolMsg = [ + { + type: "stream", + thinkMsg: thinkMsg, + val: marked(sqlValue), + }, + ]; + this.refashMsg(rolMsg); + } else if (resText.indexOf("</think>") > -1) { + let position = resText.indexOf("</think>"); + //</think>涔嬪墠鐨勫唴瀹� + const beforeText = resText.substring(0, position); + //鍒锋柊 + sqlValue += beforeText; + var rolMsg = [ + { + type: "stream", + thinkMsg: thinkMsg, + val: marked(sqlValue), + }, + ]; + this.refashMsg(rolMsg); + thinkMsg = false; + // </think>涔嬪悗鐨勫唴瀹� + const afterT = resText.substring(position + "</think>".length); + //鍒锋柊 + if (afterT) { + afterText += afterT; + var rolMsg = [ + { + type: "stream", + thinkMsg: true, + val: marked(sqlValue), + }, + { + type: "stream", + thinkMsg: false, + val: marked(afterText), + }, + ]; + this.refashMsg(rolMsg); + } + } else { + if (thinkMsg) { + sqlValue += resText; + var rolMsg = [ + { + type: "stream", + thinkMsg: thinkMsg, + val: marked(sqlValue), + }, + ]; + this.refashMsg(rolMsg); + } else { + afterText += resText; + var rolMsg = [ + { + type: "stream", + thinkMsg: true, + val: marked(sqlValue), + }, + { + type: "stream", + thinkMsg: false, + val: marked(afterText), + }, + ]; + this.refashMsg(rolMsg); + } + } + } + } catch (err) { + var rolMsg = [ + { + type: "text", + val: "鏈煡璇㈠埌鐩稿叧淇℃伅銆�", + }, + ]; + this.refashMsg(rolMsg); + } }, + setMapfunc(res, obj) { this.$store.state.showLenged = false; switch (res.func) { @@ -496,6 +669,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); -- Gitblit v1.9.3