11wqe1 2 semanas atrás
pai
commit
aaa72ae2b8

+ 16 - 27
src/components/classRoomHelper/component/languageAssistant.vue

@@ -328,7 +328,6 @@ export default {
                     model: "gpt-4o-2024-11-20"
                   };
 
-                  const md = new MarkdownIt();
                   let _this = this;
                   this.curRequestController = new AbortController();
 
@@ -336,7 +335,7 @@ export default {
                   let _mdText = "";
                   let _talkText = "";
 
-                  fetchEventSource("https://gpt4.cocorobo.cn/chat_post_stream",{
+                  fetchEventSource("https://gpt4.cocorobo.cn/ai_agent_park_chat_new_post_stream",{
                     method: "POST",
                     headers: {
                       "Content-Type": "application/json"
@@ -344,13 +343,12 @@ export default {
                     body: JSON.stringify(params),
                     signal: _this.curRequestController.signal,
                     onmessage(_e){
-                      console.log('_e',_e)
+                      // console.log('_e',_e)
 
-                      this.showIndex = 0;
+                      _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;
@@ -359,15 +357,15 @@ export default {
                           }
                         }
                         _mdText = _mdText.replace("_", "");
-                        this.aiText = _mdText;
-                        this.scrollBottom();
+                        _this.aiText = _mdText;
+                        _this.scrollBottom();
                         if (_talkText != "") {
-                          let _resultText = this.removeMarkdown(_talkText);
-                          this.talkTextList.push(_resultText);
+                          let _resultText = _this.removeMarkdown(_talkText);
+                          _this.talkTextList.push(_resultText);
                           _talkText = "";
-                          if (!this.talkLoading) this.talkText();
+                          if (!_this.talkLoading) _this.talkText();
                         }
-                        this.chatLoading = false;
+                        _this.chatLoading = false;
                       } else {
                         // _talkIndex+=1;
                         let _text = _eData.content.replace("'", "").replace("'", "");
@@ -383,25 +381,16 @@ export default {
                         _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.scrollBottom();
+                        _this.aiText = _mdText;
+                        _this.showTextIndex = 0;
+                        _this.scrollBottom();
                         if (/[,。:;?!)]/.test(_talkText)) {
-                          let _resultText = this.removeMarkdown(_talkText);
-                          this.talkTextList.push(_resultText);
+                          let _resultText = _this.removeMarkdown(_talkText);
+                          _this.talkTextList.push(_resultText);
                           _talkText = "";
-                          if (!this.talkLoading) this.talkText();
+                          if (!_this.talkLoading) _this.talkText();
                         }
                       }
-
-                      // 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();

+ 148 - 112
src/components/classRoomHelper/component/searchArea.vue

@@ -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) {