From ce6022e709c4b329785a624381fd51ad41371209 Mon Sep 17 00:00:00 2001 From: yxl <584911253@qq.com> Date: 星期一, 17 二月 2025 10:01:03 +0800 Subject: [PATCH] 模型加载地址配置 --- src/views/chartView/index.vue | 227 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 191 insertions(+), 36 deletions(-) diff --git a/src/views/chartView/index.vue b/src/views/chartView/index.vue index 5d12549..0fd05cc 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", @@ -147,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); @@ -255,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(), }; @@ -268,64 +270,205 @@ 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); + } }); + + // 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: "鎶辨瓑锛屾湇鍔″櫒浼间箮鍑轰簡鐐归棶棰橈紝鎴戜滑姝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: "鏈煡璇㈠埌鐩稿叧淇℃伅銆�", + }, + ]; + this.refashMsg(rolMsg); + return; + } + // 鐢ㄦ潵鑾峰彇涓�涓彲璇荤殑娴佺殑璇诲彇鍣紙Reader锛変互娴佺殑鏂瑰紡澶勭悊鍝嶅簲浣撴暟鎹� + const reader = response.body.getReader(); + // 灏嗘祦涓殑瀛楄妭鏁版嵁瑙g爜涓烘枃鏈瓧绗︿覆 + 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; + } + 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: "鎶辨瓑锛屾湇鍔″櫒浼间箮鍑轰簡鐐归棶棰橈紝鎴戜滑姝e湪淇涓��", - }, - ]; - this.refashMsg(rolMsg); - }); + } + // console.log(sqlValue, "杈撳嚭鎵�鏈夎繑鍥炴暟鎹�"); + } catch (err) { + var rolMsg = [ + { + type: "text", + val: "鏈煡璇㈠埌鐩稿叧淇℃伅銆�", + }, + ]; + this.refashMsg(rolMsg); + } }, setMapfunc(res, obj) { this.$store.state.showLenged = false; @@ -496,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); -- Gitblit v1.9.3