|
@@ -173,6 +173,8 @@
|
|
|
<script>
|
|
|
import { v4 as uuidv4 } from "uuid";
|
|
|
import MarkdownIt from "markdown-it";
|
|
|
+import { fetchEventSource } from "@microsoft/fetch-event-source";
|
|
|
+
|
|
|
export default {
|
|
|
props: {},
|
|
|
data() {
|
|
@@ -193,6 +195,8 @@ export default {
|
|
|
openMessage: true,
|
|
|
canTalk:true,
|
|
|
loading:false,
|
|
|
+ curRequestController:null,
|
|
|
+
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
@@ -321,54 +325,148 @@ export default {
|
|
|
session_name: _uuid + "-qgt",
|
|
|
uid: _uuid,
|
|
|
file_ids: [],
|
|
|
- model: "gpt-4o-2024-11-20"
|
|
|
+ model: "gpt-4o-2024-11-20",
|
|
|
+ stream:true
|
|
|
};
|
|
|
- this.ajax
|
|
|
- // .post("https://claude3.cocorobo.cn/chat", params)
|
|
|
- // .post("https://gpt4.cocorobo.cn/chat", params)
|
|
|
- .post(
|
|
|
- "https://gpt4.cocorobo.cn/ai_agent_park_chat_new",
|
|
|
- params
|
|
|
- )
|
|
|
- .then(res => {
|
|
|
- if (
|
|
|
- converter(res.data.FunctionResponse.result) ==
|
|
|
- converter("发送成功")
|
|
|
- ) {
|
|
|
- this.userText = "";
|
|
|
- this.showIndex = 0;
|
|
|
- } else {
|
|
|
- // this.$message.warning(res.data.FunctionResponse.result);
|
|
|
- console.log(res.data.FunctionResponse.result);
|
|
|
+
|
|
|
+ const md = new MarkdownIt();
|
|
|
+ let _this = this;
|
|
|
+ this.curRequestController = new AbortController();
|
|
|
+
|
|
|
+ let _allText = "";
|
|
|
+ let _mdText = "";
|
|
|
+ let _talkText = "";
|
|
|
+
|
|
|
+ fetchEventSource("https://gpt4.cocorobo.cn/chat_post_stream",{
|
|
|
+ method: "POST",
|
|
|
+ headers: {
|
|
|
+ "Content-Type": "application/json"
|
|
|
+ },
|
|
|
+ body: JSON.stringify(params),
|
|
|
+ signal: _this.curRequestController.signal,
|
|
|
+ onmessage(_e){
|
|
|
+ console.log('_e',_e)
|
|
|
+
|
|
|
+ this.showIndex = 0;
|
|
|
+ let _eData = JSON.parse(_e.data);
|
|
|
+ if (_eData.content.replace("'", "").replace("'", "") == "[DONE]") {
|
|
|
+ // this.source.close();
|
|
|
+ // this.source = null;
|
|
|
+ let _result = [];
|
|
|
+ if ("result" in _eData) {
|
|
|
+ _result = _eData.result;
|
|
|
+ for (let i = 0; i < _result.length; i++) {
|
|
|
+ _mdText = _mdText.replace(_result[i].text, _result[i].fileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _mdText = _mdText.replace("_", "");
|
|
|
+ this.aiText = _mdText;
|
|
|
+ this.scrollBottom();
|
|
|
+ if (_talkText != "") {
|
|
|
+ let _resultText = this.removeMarkdown(_talkText);
|
|
|
+ this.talkTextList.push(_resultText);
|
|
|
+ _talkText = "";
|
|
|
+ if (!this.talkLoading) this.talkText();
|
|
|
+ }
|
|
|
this.chatLoading = false;
|
|
|
- this.aiStatus = 0;
|
|
|
+ } else {
|
|
|
+ // _talkIndex+=1;
|
|
|
+ let _text = _eData.content.replace("'", "").replace("'", "");
|
|
|
+ if (_allText == "") {
|
|
|
+ _allText = _text.replace(/^\n+/, ""); //去掉回复消息中偶尔开头就存在的连续换行符
|
|
|
+ _talkText += _text.replace(/^\n+/, "");
|
|
|
+ } else {
|
|
|
+ _allText += _text;
|
|
|
+ _talkText += _text;
|
|
|
+ }
|
|
|
+ `~`;
|
|
|
+ _mdText = _allText + "_";
|
|
|
+ _mdText = _mdText.replace(/\\n/g, "\n");
|
|
|
+ _mdText = _mdText.replace(/\\/g, "");
|
|
|
+ if (_allText.split("```").length % 2 == 0) _mdText += "\n```\n";
|
|
|
+ this.aiText = _mdText;
|
|
|
this.showTextIndex = 0;
|
|
|
- this.showIndex = 0;
|
|
|
- this.aiText = "对不起,我无法理解您的问题,请重新提问";
|
|
|
- // this.timer = setTimeout(() => {
|
|
|
- // this.showTextIndex = 3;
|
|
|
- // this.aiStatus = 2;
|
|
|
- // this.aiText = "";
|
|
|
- // this.userText = "";
|
|
|
- // }, 3000);
|
|
|
+ this.scrollBottom();
|
|
|
+ if (/[,。:;?!)]/.test(_talkText)) {
|
|
|
+ let _resultText = this.removeMarkdown(_talkText);
|
|
|
+ this.talkTextList.push(_resultText);
|
|
|
+ _talkText = "";
|
|
|
+ if (!this.talkLoading) this.talkText();
|
|
|
+ }
|
|
|
}
|
|
|
- })
|
|
|
- .catch(e => {
|
|
|
- console.log(e);
|
|
|
- this.chatLoading = false;
|
|
|
- this.aiStatus = 0;
|
|
|
- this.showTextIndex = 0;
|
|
|
- this.showIndex = 0;
|
|
|
- this.aiText = "对不起,我无法理解您的问题,请重新提问";
|
|
|
- // this.timer = setTimeout(() => {
|
|
|
- // this.showTextIndex = 3;
|
|
|
- // this.aiStatus = 2;
|
|
|
- // this.aiText = "";
|
|
|
- // this.userText = "";
|
|
|
- // }, 3000);
|
|
|
- });
|
|
|
- // 通过流获取ai对话数据
|
|
|
- this.getAtAuContent(_uuid);
|
|
|
+
|
|
|
+ // let _data = ev.data;
|
|
|
+ // if(_data=='[DONE]')return;
|
|
|
+ // _addText+=_data;
|
|
|
+ // this.aiText = md.render(_addText)
|
|
|
+ // // _this.chatList.find(i => i.uid == _uuid).aiContent = md.render(_addText);
|
|
|
+ // // _this.chatList.find(i => i.uid == _uuid).loading = false;
|
|
|
+ // _this.scrollBottom();
|
|
|
+ // console.log(_data)
|
|
|
+ },
|
|
|
+ onclose(){
|
|
|
+ _this.$forceUpdate();
|
|
|
+ // _this.stopTalkToken = null;
|
|
|
+ // // _this.faloading = false;
|
|
|
+ // _this.curRequestController = null;
|
|
|
+
|
|
|
+ // _this.chatList.find(i => i.uid == _uuid).isalltext = true;
|
|
|
+ // _this.chatList.find(i => i.uid == _uuid).isShowSynchronization = true;
|
|
|
+ // _this.insertChat(_uuid);
|
|
|
+ console.log("连接关闭")
|
|
|
+ },
|
|
|
+ onerror(err){
|
|
|
+
|
|
|
+ console.log("连接错误",err)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // this.ajax
|
|
|
+ // // .post("https://claude3.cocorobo.cn/chat", params)
|
|
|
+ // // .post("https://gpt4.cocorobo.cn/chat", params)
|
|
|
+ // .post(
|
|
|
+ // "https://gpt4.cocorobo.cn/ai_agent_park_chat_new",
|
|
|
+ // params
|
|
|
+ // )
|
|
|
+ // .then(res => {
|
|
|
+ // if (
|
|
|
+ // converter(res.data.FunctionResponse.result) ==
|
|
|
+ // converter("发送成功")
|
|
|
+ // ) {
|
|
|
+ // this.userText = "";
|
|
|
+ // this.showIndex = 0;
|
|
|
+ // } else {
|
|
|
+ // // this.$message.warning(res.data.FunctionResponse.result);
|
|
|
+ // console.log(res.data.FunctionResponse.result);
|
|
|
+ // this.chatLoading = false;
|
|
|
+ // this.aiStatus = 0;
|
|
|
+ // this.showTextIndex = 0;
|
|
|
+ // this.showIndex = 0;
|
|
|
+ // this.aiText = "对不起,我无法理解您的问题,请重新提问";
|
|
|
+ // // this.timer = setTimeout(() => {
|
|
|
+ // // this.showTextIndex = 3;
|
|
|
+ // // this.aiStatus = 2;
|
|
|
+ // // this.aiText = "";
|
|
|
+ // // this.userText = "";
|
|
|
+ // // }, 3000);
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // .catch(e => {
|
|
|
+ // console.log(e);
|
|
|
+ // this.chatLoading = false;
|
|
|
+ // this.aiStatus = 0;
|
|
|
+ // this.showTextIndex = 0;
|
|
|
+ // this.showIndex = 0;
|
|
|
+ // this.aiText = "对不起,我无法理解您的问题,请重新提问";
|
|
|
+ // // this.timer = setTimeout(() => {
|
|
|
+ // // this.showTextIndex = 3;
|
|
|
+ // // this.aiStatus = 2;
|
|
|
+ // // this.aiText = "";
|
|
|
+ // // this.userText = "";
|
|
|
+ // // }, 3000);
|
|
|
+ // });
|
|
|
+ // // 通过流获取ai对话数据
|
|
|
+ // this.getAtAuContent(_uuid);
|
|
|
}
|
|
|
}, 5000);
|
|
|
}
|