|
@@ -647,6 +647,7 @@ let converter = OpenCC.Converter({
|
|
|
from: "cn",
|
|
|
to: "hk"
|
|
|
});
|
|
|
+import { fetchEventSource } from "@microsoft/fetch-event-source";
|
|
|
const clickOutside = {
|
|
|
bind(el, binding) {
|
|
|
// 在元素上绑定一个点击事件监听器
|
|
@@ -1356,7 +1357,7 @@ ${fileText}
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
- addContent() {
|
|
|
+ addContent2() {
|
|
|
if (this.courseText.trim().length == 0) {
|
|
|
return this.$message.error("请输入内容");
|
|
|
} else if (this.fileList.length == 0) {
|
|
@@ -1507,7 +1508,7 @@ ${fileText}
|
|
|
// this.saveUid = _uuid;
|
|
|
}
|
|
|
},
|
|
|
- async addContent2() {
|
|
|
+ async addContent() {
|
|
|
if (this.courseText.trim().length == 0) {
|
|
|
return this.$message.error("请输入内容");
|
|
|
} else if (this.fileList.length == 0) {
|
|
@@ -1561,82 +1562,137 @@ ${fileText}
|
|
|
});
|
|
|
this.courseText = "";
|
|
|
this.saveUid = _uuid;
|
|
|
+ let _addText = "";
|
|
|
+ const md = new MarkdownIt();
|
|
|
+ let _this = this;
|
|
|
const curRequestController = new AbortController();
|
|
|
- fetch("https://gpt4.cocorobo.cn/csvaimessagestream", {
|
|
|
+ fetchEventSource("https://gpt4.cocorobo.cn/csvaimessagestream",{
|
|
|
method: "POST",
|
|
|
headers: {
|
|
|
"Content-Type": "application/json"
|
|
|
},
|
|
|
body: JSON.stringify(params),
|
|
|
- signal: curRequestController.signal
|
|
|
- })
|
|
|
- .then(res => {
|
|
|
- console.log("👉", res);
|
|
|
- let reader = res.body.getReader();
|
|
|
- let getStream = reader => {
|
|
|
- return reader.read().then(result => {
|
|
|
- if (result.done) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //取出数据(二进制)
|
|
|
- let chunk = result.value;
|
|
|
- let _text = ``;
|
|
|
- for (let i = 0; i < chunk.byteLength; i++) {
|
|
|
- _text += String.fromCharCode(chunk[i]);
|
|
|
- }
|
|
|
-
|
|
|
- let resultObj = JSON.parse(_text);
|
|
|
-
|
|
|
- if (resultObj["actions"]) {
|
|
|
- let data = resultObj["actions"];
|
|
|
- console.log("👉:",data)
|
|
|
- const md = new MarkdownIt();
|
|
|
- const text = md.render(data);
|
|
|
- this.array.find(i => i.uid == _uuid).aiContent = text;
|
|
|
- this.array.find(i => i.uid == _uuid).loading = false;
|
|
|
- this.$nextTick(() => {
|
|
|
- this.$refs.chatDialog.scrollTop = this.$refs.chatDialog.scrollHeight;
|
|
|
- });;
|
|
|
- } else if (resultObj["steps"]) {
|
|
|
- let data = resultObj["steps"];
|
|
|
- console.log("👉:",data)
|
|
|
- const md = new MarkdownIt();
|
|
|
- const text = md.render(data);
|
|
|
- this.array.find(i => i.uid == _uuid).aiContent = text;
|
|
|
- this.array.find(i => i.uid == _uuid).loading = false;
|
|
|
- this.$nextTick(() => {
|
|
|
- this.$refs.chatDialog.scrollTop = this.$refs.chatDialog.scrollHeight;
|
|
|
- });
|
|
|
- } else if (resultObj["output"]) {
|
|
|
- let data = resultObj["output"];
|
|
|
- console.log("👉:",data)
|
|
|
- const md = new MarkdownIt();
|
|
|
- const text = md.render(data);
|
|
|
- this.array.find(i => i.uid == _uuid).aiContent = text;
|
|
|
- this.array.find(i => i.uid == _uuid).isalltext = true;
|
|
|
- this.array.find(i => i.uid == _uuid).isShowSynchronization = true;
|
|
|
- this.array.find(i => i.uid == _uuid).loading = false;
|
|
|
- this.array.find(i => i.uid == _uuid).mdText = data;
|
|
|
- this.$forceUpdate();
|
|
|
- this.stopTalkToken = null;
|
|
|
- this.faloading = false;
|
|
|
- this.generateChart(this.array.find(i => i.uid == _uuid));
|
|
|
- this.$nextTick(() => {
|
|
|
- this.$refs.chatDialog.scrollTop = this.$refs.chatDialog.scrollHeight;
|
|
|
- });
|
|
|
- this.insertChat(_uuid);
|
|
|
- }
|
|
|
+ signal: curRequestController.signal,
|
|
|
+ onmessage(ev){
|
|
|
+ let _data = JSON.parse(ev.data);
|
|
|
+ console.log("👉>>>",_data)
|
|
|
+ let _text = _data.data;
|
|
|
+ let status = _data.event;
|
|
|
+ if(status=='on_chain_start'){
|
|
|
+ const text = md.render('开始分析数据\n')
|
|
|
+ _this.array.find(i => i.uid == _uuid).aiContent += text
|
|
|
+ }else if(status=='on_tool_start'){
|
|
|
+ const text = md.render('开始调用工具代码\n')
|
|
|
+ _this.array.find(i => i.uid == _uuid).aiContent += text
|
|
|
+ }else if(status=='on_tool_end'){
|
|
|
+ const text = md.render('调用工具代码成功返回数据\n')
|
|
|
+ _this.array.find(i => i.uid == _uuid).aiContent += text
|
|
|
+ }else if(status=='on_chat_model_stream'){
|
|
|
+ _addText+=_text;
|
|
|
+ const text = md.render(_addText);
|
|
|
+ _this.array.find(i => i.uid == _uuid).loading = false;
|
|
|
+ _this.array.find(i => i.uid == _uuid).aiContent = text;
|
|
|
+ }else if(status=='on_chain_end'){
|
|
|
+ const text = md.render(_text);
|
|
|
+ _this.array.find(i => i.uid == _uuid).aiContent = text;
|
|
|
+ _this.array.find(i => i.uid == _uuid).loading = false;
|
|
|
+ _this.array.find(i => i.uid == _uuid).mdText = _text;
|
|
|
+ _this.generateChart(_this.array.find(i => i.uid == _uuid));
|
|
|
+ _this.insertChat(_uuid);
|
|
|
+ }
|
|
|
+ _this.$nextTick(() => {
|
|
|
+ _this.$refs.chatDialog.scrollTop = _this.$refs.chatDialog.scrollHeight;
|
|
|
+ });;
|
|
|
+ },
|
|
|
+ onclose(){
|
|
|
+ _this.$forceUpdate();
|
|
|
+ _this.stopTalkToken = null;
|
|
|
+ _this.faloading = false;
|
|
|
+ console.log("连接关闭")
|
|
|
+ },
|
|
|
+ onerror(err){
|
|
|
+ console.log("连接错误",err)
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
- // 递归下一个
|
|
|
- return getStream(reader);
|
|
|
- });
|
|
|
- };
|
|
|
- getStream(reader);
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.log(err);
|
|
|
- });
|
|
|
+ // fetch("https://gpt4.cocorobo.cn/csvaimessagestream", {
|
|
|
+ // method: "POST",
|
|
|
+ // headers: {
|
|
|
+ // "Content-Type": "application/json"
|
|
|
+ // },
|
|
|
+ // body: JSON.stringify(params),
|
|
|
+ // signal: curRequestController.signal
|
|
|
+ // })
|
|
|
+ // .then(res => {
|
|
|
+ // let reader = res.body.getReader();
|
|
|
+ // let getStream = reader => {
|
|
|
+ // return reader.read().then(result => {
|
|
|
+ // if (result.done) {
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // //取出数据(二进制)
|
|
|
+ // let chunk = result.value;
|
|
|
+ // let _text = ``;
|
|
|
+ // for (let i = 0; i < chunk.byteLength; i++) {
|
|
|
+ // _text += String.fromCharCode(chunk[i]);
|
|
|
+ // }
|
|
|
+ // _text = _text.replace('data','"data"');
|
|
|
+ // console.log("👉!!!!",_text,"<<<👈")
|
|
|
+
|
|
|
+ // // let resultObj = JSON.parse(_text);
|
|
|
+ // // console.log("👉》》》",resultObj)
|
|
|
+
|
|
|
+ // // if (resultObj["event"]=='on_chat_model_stream') {
|
|
|
+ // // let data = resultObj["data"];
|
|
|
+ // // console.log("👉:",data)
|
|
|
+ // // const md = new MarkdownIt();
|
|
|
+ // // const text = md.render(data);
|
|
|
+ // // this.array.find(i => i.uid == _uuid).aiContent = text;
|
|
|
+ // // this.array.find(i => i.uid == _uuid).loading = false;
|
|
|
+ // // this.$nextTick(() => {
|
|
|
+ // // this.$refs.chatDialog.scrollTop = this.$refs.chatDialog.scrollHeight;
|
|
|
+ // // });;
|
|
|
+ // // }
|
|
|
+ // // } else if (resultObj["steps"]) {
|
|
|
+ // // let data = resultObj["steps"];
|
|
|
+ // // console.log("👉:",data)
|
|
|
+ // // const md = new MarkdownIt();
|
|
|
+ // // const text = md.render(data);
|
|
|
+ // // this.array.find(i => i.uid == _uuid).aiContent = text;
|
|
|
+ // // this.array.find(i => i.uid == _uuid).loading = false;
|
|
|
+ // // this.$nextTick(() => {
|
|
|
+ // // this.$refs.chatDialog.scrollTop = this.$refs.chatDialog.scrollHeight;
|
|
|
+ // // });
|
|
|
+ // // } else if (resultObj["output"]) {
|
|
|
+ // // let data = resultObj["output"];
|
|
|
+ // // console.log("👉:",data)
|
|
|
+ // // const md = new MarkdownIt();
|
|
|
+ // // const text = md.render(data);
|
|
|
+ // // this.array.find(i => i.uid == _uuid).aiContent = text;
|
|
|
+ // // this.array.find(i => i.uid == _uuid).isalltext = true;
|
|
|
+ // // this.array.find(i => i.uid == _uuid).isShowSynchronization = true;
|
|
|
+ // // this.array.find(i => i.uid == _uuid).loading = false;
|
|
|
+ // // this.array.find(i => i.uid == _uuid).mdText = data;
|
|
|
+ // // this.$forceUpdate();
|
|
|
+ // // this.stopTalkToken = null;
|
|
|
+ // // this.faloading = false;
|
|
|
+ // // this.generateChart(this.array.find(i => i.uid == _uuid));
|
|
|
+ // // this.$nextTick(() => {
|
|
|
+ // // this.$refs.chatDialog.scrollTop = this.$refs.chatDialog.scrollHeight;
|
|
|
+ // // });
|
|
|
+ // // this.insertChat(_uuid);
|
|
|
+ // // }
|
|
|
+
|
|
|
+ // // 递归下一个
|
|
|
+ // return getStream(reader);
|
|
|
+ // });
|
|
|
+ // };
|
|
|
+ // getStream(reader);
|
|
|
+ // })
|
|
|
+ // .catch(err => {
|
|
|
+ // console.log(err);
|
|
|
+ // });
|
|
|
}
|
|
|
},
|
|
|
async getData() {
|
|
@@ -2314,6 +2370,7 @@ ${fileText}
|
|
|
}
|
|
|
},
|
|
|
async generateChart(item) {
|
|
|
+ console.log("生成图表")
|
|
|
let _eChartsMsg = `
|
|
|
折线图(type=0):{"xAxis":{"type":"category","data":["data1","data2","data3","data4","data5","data6","data7"]},"yAxis":{"type":"value"},"series":[{"data":[150,230,224,218,135,147,260],"type":"line"}]}
|
|
|
折线图堆叠(type=1):{"tooltip":{"trigger":"axis"},"legend":{"data":["data1","data2","data3","data4","data5"]},"grid":{"left":"3%","right":"4%","bottom":"3%","containLabel":true},"toolbox":{"feature":{"saveAsImage":{}}},"xAxis":{"type":"category","boundaryGap":false,"data":["xdata1","xdata2","xdata3","xdata4","xdata5","xdata6","xdata7"]},"yAxis":{"type":"value"},"series":[{"name":"data1","type":"line","stack":"Total","data":[120,132,101,134,90,230,210]},{"name":"data2","type":"line","stack":"Total","data":[220,182,191,234,290,330,310]},{"name":"data3","type":"line","stack":"Total","data":[150,232,201,154,190,330,410]},{"name":"data4","type":"line","stack":"Total","data":[320,332,301,334,390,330,320]},{"name":"data5","type":"line","stack":"Total","data":[820,932,901,934,1290,1330,1320]}]}
|