|
@@ -2108,26 +2108,132 @@ export default {
|
|
|
// };
|
|
|
this.text = "";
|
|
|
|
|
|
- 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("发送成功")
|
|
|
- ) {
|
|
|
+ let _allText = "";
|
|
|
+ let _mdText = "";
|
|
|
+ let _index = 0;
|
|
|
+ let _talkText = "";
|
|
|
+ let _this = this
|
|
|
+ this.curRequestController = new AbortController();
|
|
|
+
|
|
|
+ fetchEventSource("https://gpt4.cocorobo.cn/ai_agent_park_chat_new_post_stream",{
|
|
|
+ method: "POST",
|
|
|
+ headers: {
|
|
|
+ "Content-Type": "application/json"
|
|
|
+ },
|
|
|
+ body: JSON.stringify(params),
|
|
|
+ signal: _this.curRequestController.signal,
|
|
|
+ onmessage(_e){
|
|
|
+ // console.log('_e_e_e_e_e_e_e_e_e',_e);
|
|
|
+
|
|
|
+ let _eData = JSON.parse(_e.data);
|
|
|
+ if (_eData.content.replace("'", "").replace("'", "") == "[DONE]") {
|
|
|
+ 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("_", "");
|
|
|
+ if (_this.openMegaphone && _this.aiTalkUid == _uuid) {
|
|
|
+ if (_talkText != "") {
|
|
|
+ let _resultText = _this.removeMarkdown(_talkText);
|
|
|
+ _this.aiTalkList.push(_resultText);
|
|
|
+ _talkText = "";
|
|
|
+ if (!_this.aiIsTalk) _this.aiTalk(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _this.chatLoading = false;
|
|
|
+ _this.chatList.find(i => i.uid == _uuid).aiContent = _mdText;
|
|
|
+ _this.chatList.find(i => i.uid == _uuid).isalltext = true;
|
|
|
+ _this.chatList.find(i => i.uid == _uuid).isShowSynchronization = true;
|
|
|
+ _this.chatList.find(i => i.uid == _uuid).loading = false;
|
|
|
+ _this.nowChatList.push(_this.chatList.find(i => i.uid == _uuid));
|
|
|
+ // this.addAsk(this.chatList.find(i => i.uid == _uid).content);
|
|
|
+ // this.source.close();
|
|
|
+ _this.insertChat(_uuid);
|
|
|
} else {
|
|
|
- // this.$message.warning(res.data.FunctionResponse.result);
|
|
|
- console.log(res.data.FunctionResponse.result);
|
|
|
- this.chatLoading = false;
|
|
|
+ _index += 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";
|
|
|
+ //转化返回的回复流数据
|
|
|
+ // _mdText = md.render(_mdText);
|
|
|
+ if (_index == 10) {
|
|
|
+ _this.chatList.find(i => i.uid == _uuid).aiContent = _mdText;
|
|
|
+ _this.chatList.find(i => i.uid == _uuid).loading = false;
|
|
|
+ _this.$nextTick(() => {
|
|
|
+ _this.$refs.chatRef.scrollTop = _this.$refs.chatRef.scrollHeight;
|
|
|
+ });
|
|
|
+ _index = 0;
|
|
|
+ }
|
|
|
+ if (_this.openMegaphone && /[,。:;?!)]/.test(_talkText)) {
|
|
|
+ let _resultText = _this.removeMarkdown(_talkText);
|
|
|
+ if (_this.aiTalkUid != _uuid) {
|
|
|
+ _this.aiTalkList = [];
|
|
|
+ }
|
|
|
+ _this.aiTalkList.push(_resultText);
|
|
|
+ _talkText = "";
|
|
|
+ if (_this.aiTalkUid != _uuid) {
|
|
|
+ _this.aiTalkUid = _uuid;
|
|
|
+ _this.aiTalk(0);
|
|
|
+ } else if (!_this.aiIsTalk) {
|
|
|
+ _this.aiTalk(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 处理流数据
|
|
|
}
|
|
|
- })
|
|
|
- .catch(e => {
|
|
|
- console.log(e);
|
|
|
- this.chatLoading = false;
|
|
|
- });
|
|
|
+ },
|
|
|
+ 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("发送成功")
|
|
|
+ // ) {
|
|
|
+ // console.log('555');
|
|
|
+
|
|
|
+
|
|
|
+ // } else {
|
|
|
+ // // this.$message.warning(res.data.FunctionResponse.result);
|
|
|
+ // console.log('6666');
|
|
|
+
|
|
|
+ // console.log(res.data.FunctionResponse.result);
|
|
|
+ // this.chatLoading = false;
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // .catch(e => {
|
|
|
+ // console.log(e);
|
|
|
+ // this.chatLoading = false;
|
|
|
+ // });
|
|
|
this.saveUid = _uuid;
|
|
|
- this.getAtAuContent(_uuid);
|
|
|
+ // this.getAtAuContent(_uuid);
|
|
|
},
|
|
|
atSend(_text, _atList) {
|
|
|
let _msg = ``;
|
|
@@ -2709,8 +2815,7 @@ Instruction: Based on the context, follow "Format example", write content
|
|
|
session_name: _uuid,
|
|
|
// uid: _uuid,
|
|
|
file_ids: this.fileId,
|
|
|
- model: "gpt-4o-2024-11-20",
|
|
|
- stream:true
|
|
|
+ model: "gpt-4o-2024-11-20"
|
|
|
};
|
|
|
// let params = {
|
|
|
// message: {
|
|
@@ -2725,99 +2830,30 @@ Instruction: Based on the context, follow "Format example", write content
|
|
|
// };
|
|
|
this.text = "";
|
|
|
|
|
|
- let _allText = "";
|
|
|
- let _mdText = "";
|
|
|
-
|
|
|
- const md = new MarkdownIt();
|
|
|
- let _this = this;
|
|
|
- // const curRequestController = new AbortController();
|
|
|
- this.curRequestController = new AbortController();
|
|
|
-
|
|
|
- fetchEventSource("https://gpt4.cocorobo.cn/ai_agent_park_chat_new_post_stream",{
|
|
|
- method: "POST",
|
|
|
- headers: {
|
|
|
- "Content-Type": "application/json"
|
|
|
- },
|
|
|
- body: JSON.stringify(params),
|
|
|
- signal: _this.curRequestController.signal,
|
|
|
- onmessage(_e){
|
|
|
- if (_e.data.replace("'", "").replace("'", "") == "[DONE]") {
|
|
|
- //对话已经完成
|
|
|
- _mdText = _mdText.replace("_", "");
|
|
|
- _mdText = _mdText.replace("```json", "");
|
|
|
- _mdText = _mdText.replace("```", "");
|
|
|
- // 使用正则表达式匹配JSON数组
|
|
|
- const regex = /\[\s*{[^]*}\s*\]/;
|
|
|
- const match = _mdText.match(regex);
|
|
|
- let _result = match[0];
|
|
|
- source.close();
|
|
|
- this.chatList.find(i => i.uid == _uuid).aiContent = JSON.parse(
|
|
|
- _result
|
|
|
- );
|
|
|
- this.chatList.find(i => i.uid == _uuid).isalltext = true;
|
|
|
- this.chatList.find(i => i.uid == _uuid).isShowSynchronization = true;
|
|
|
- this.chatList.find(i => i.uid == _uuid).loading = false;
|
|
|
- this.nowChatList.push(this.chatList.find(i => i.uid == _uuid));
|
|
|
- this.scrollBottom();
|
|
|
- // 这里保存对话
|
|
|
- return;
|
|
|
- } else {
|
|
|
- //对话还在继续
|
|
|
- let _text = "";
|
|
|
- _text = _e.data.replaceAll("'", "");
|
|
|
- if (_allText == "") {
|
|
|
- _allText = _text.replace(/^\n+/, ""); //去掉回复消息中偶尔开头就存在的连续换行符
|
|
|
- } else {
|
|
|
- _allText += _text;
|
|
|
- }
|
|
|
- _mdText = _allText + "_";
|
|
|
- _mdText = _mdText.replace(/\\n/g, "\n");
|
|
|
- _mdText = _mdText.replace(/\\/g, "");
|
|
|
- if (_allText.split("```").length % 2 == 0) _mdText += "\n```\n";
|
|
|
- //转化返回的回复流数据
|
|
|
- this.scrollBottom();
|
|
|
- }
|
|
|
- },
|
|
|
- onclose(){
|
|
|
- _this.$forceUpdate();
|
|
|
- // _this.stopTalkToken = null;
|
|
|
- // _this.faloading = false;
|
|
|
- _this.curRequestController = null;
|
|
|
- // _this.chatList.find(i => i.uid == _uid).isalltext = true;
|
|
|
- // _this.chatList.find(i => i.uid == _uid).isShowSynchronization = true;
|
|
|
- _this.insertChat(_uuid);
|
|
|
- console.log("连接关闭")
|
|
|
- },
|
|
|
- onerror(err){
|
|
|
-
|
|
|
- console.log("连接错误",err)
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- // this.ajax
|
|
|
- // // .post("https://gpt4.cocorobo.cn/chat", params)
|
|
|
- // // .post("https://claude3.cocorobo.cn/chat", params)
|
|
|
- // .post("https://gpt4.cocorobo.cn/ai_agent_park_chat", params)
|
|
|
- // .then(res => {
|
|
|
- // // console.log(res);
|
|
|
- // let _data = res.data.FunctionResponse.message;
|
|
|
- // _data = _data.replaceAll("```json", "").replaceAll("```", "");
|
|
|
- // const match = _data.match(/\[\s*{[^]*}\s*\]/);
|
|
|
- // // console.log(_data);
|
|
|
- // // console.log(match);
|
|
|
- // this.chatList.find(i => i.uid == _uuid).aiContent = JSON.parse(
|
|
|
- // match[0]
|
|
|
- // );
|
|
|
- // this.chatList.find(i => i.uid == _uuid).isalltext = true;
|
|
|
- // this.chatList.find(i => i.uid == _uuid).isShowSynchronization = true;
|
|
|
- // this.chatList.find(i => i.uid == _uuid).loading = false;
|
|
|
- // this.scrollBottom();
|
|
|
- // // this.chatLoading = false;
|
|
|
- // })
|
|
|
- // .catch(e => {
|
|
|
- // this.chatLoading = false;
|
|
|
- // console.log(e);
|
|
|
- // });
|
|
|
+ this.ajax
|
|
|
+ // .post("https://gpt4.cocorobo.cn/chat", params)
|
|
|
+ // .post("https://claude3.cocorobo.cn/chat", params)
|
|
|
+ .post("https://gpt4.cocorobo.cn/ai_agent_park_chat", params)
|
|
|
+ .then(res => {
|
|
|
+ // console.log(res);
|
|
|
+ let _data = res.data.FunctionResponse.message;
|
|
|
+ _data = _data.replaceAll("```json", "").replaceAll("```", "");
|
|
|
+ const match = _data.match(/\[\s*{[^]*}\s*\]/);
|
|
|
+ // console.log(_data);
|
|
|
+ // console.log(match);
|
|
|
+ this.chatList.find(i => i.uid == _uuid).aiContent = JSON.parse(
|
|
|
+ match[0]
|
|
|
+ );
|
|
|
+ this.chatList.find(i => i.uid == _uuid).isalltext = true;
|
|
|
+ this.chatList.find(i => i.uid == _uuid).isShowSynchronization = true;
|
|
|
+ this.chatList.find(i => i.uid == _uuid).loading = false;
|
|
|
+ this.scrollBottom();
|
|
|
+ // this.chatLoading = false;
|
|
|
+ })
|
|
|
+ .catch(e => {
|
|
|
+ this.chatLoading = false;
|
|
|
+ console.log(e);
|
|
|
+ });
|
|
|
// this.getWAntSearchContent(_uuid);
|
|
|
},
|
|
|
addAsk(_text) {
|