SanHQin 8 months ago
parent
commit
989c71b689

+ 33 - 25
src/components/classRoomHelper/component/levitatedSphere.vue

@@ -63,7 +63,7 @@ export default {
       aiStatus: 0,
       aiText: "您好,我是小可,有什么可以帮助您的?",
       userText: "",
-      showTextIndex: 0, //0:ai,1:用户, 2:组织语言
+      showTextIndex: 0, //0:ai,1:用户, 2:组织语言  3: 无
       timer: null,
 			isOpen:false,
 			userId:this.$route.query.userid,
@@ -102,15 +102,17 @@ export default {
           // let _msg = _text;
           console.log("👇");
           console.log(_msg);
+					if(!_msg)return console.log('输出为空');
           if (_msg.indexOf("可可同学") != -1 && !this.show) {
             this.aiText = "您好,我是小可,有什么可以帮助您的?";
             this.aiStatus = 0;
             this.showIndex = 0;
             this.show = true;
             console.log("已唤醒");
+						return;
           } else if (this.show == true) {
             if (this.showTextIndex == 2 || this.chatLoading || this.talkLoading) {
-              console.log("组织语言中");
+              return console.log("组织语言中");
             } else {
               this.showTextIndex = 1;
               this.aiText = "";
@@ -128,13 +130,14 @@ export default {
                     this.aiStatus = 2;
                     this.aiText = "";
                     this.userText = "";
+										this.stopRecord();
 										return;
 									// },1000)
 								}
                 this.showTextIndex = 2;
                 this.aiText = "";
                 if (/计时(.+)分钟/.test(this.userText)) {
-                  setTimeout(() => {
+                  // setTimeout(() => {
 										let _number = this.userText.match(/计时(.+)分钟/)[1]
 										let _time = 0;
 										if(!/^\d+$/.test(_number)){
@@ -152,8 +155,8 @@ export default {
 											this.aiStatus = 2;
 											this.aiText = "";
 											this.userText = "";
-										}, 2000);
-                  }, 2000);
+										}, 3000);
+                  // }, 2000);
 								} else {
 									this.chatLoading = true;
 									const _uuid = uuidv4();
@@ -161,7 +164,7 @@ export default {
       						  assistant_id: 'f8e1ebb2-2e0d-11ef-8bf4-12e77c4cb76b',
       						  userId: this.userId,
       						  message: this.userText,
-      						  session_name: _uuid,
+      						  session_name: _uuid+"-qgt",
 										uid:_uuid,
       						  file_ids: [],
       						};
@@ -172,7 +175,18 @@ export default {
         					.then(res => {
         					  if (res.data.FunctionResponse.result == "发送成功") {
         					  } else {
-        					    this.$message.warning(res.data.FunctionResponse.result);
+        					    // this.$message.warning(res.data.FunctionResponse.result);
+											console.log(res.data.FunctionResponse.result)
+											this.chatLoading = false;
+											this.aiStatus = 0;
+                    	this.showTextIndex = 0;
+                    	this.aiText = "对不起,我无法理解您的问题,请重新提问";
+                    	this.timer = setTimeout(() => {
+                    	  this.showTextIndex = 3;
+                    	  this.aiStatus = 2;
+                    	  this.aiText = "";
+                    	  this.userText = "";
+                    	}, 3000);
         					  }
         					})
         					.catch(e => {
@@ -302,17 +316,9 @@ export default {
           }
           _mdText = _mdText.replace("_", "");
 					this.aiText = _mdText;
-					_talkIndex = 0;
 					if(_talkText!=''){
 						this.talkTextList.push(_talkText)
-					}
-					if(!this.talkLoading){
-						this.timer = setTimeout(() => {
-        		  this.showTextIndex = 3;
-        		  this.aiStatus = 2;
-        		  this.aiText = "";
-        		  this.userText = "";
-        		}, 3000);
+						if(!this.talkLoading)this.talkText();
 					}
 					this.chatLoading = false;
           this.source.close();
@@ -348,6 +354,10 @@ export default {
 			
 			if(_text){
 				this.talkLoading = true;
+				 if (this.timer) {
+          clearTimeout(this.timer);
+          this.timer = null;
+        }
 				console.log(`👉转语音:${_text}`)
 				// setTimeout(()=>{
 				// 	this.talkText();
@@ -356,16 +366,14 @@ export default {
 			}else{
 				console.log("👉转语音结束👈")
 				_talkTextIiframe2.contentWindow.closesynthesizer()
-				this.chatLoading = false;
 				this.talkLoading = false;
-				this.talkTextList = [];
-				this.timer = setTimeout(() => {
-          this.showTextIndex = 3;
-          this.aiStatus = 2;
-          this.aiText = "";
-          this.userText = "";
-        }, 3000);
-				return
+				// this.timer = setTimeout(() => {
+        //   this.showTextIndex = 3;
+        //   this.aiStatus = 2;
+        //   this.aiText = "";
+        //   this.userText = "";
+				// 	this.time = null;
+        // }, 5000);
 			}
 		},
   },

+ 8 - 3
src/components/classRoomHelper/component/searchArea.vue

@@ -1340,10 +1340,14 @@ ${_atList
           _mdText = _mdText.replace("_", "");
           _mdText = _mdText.replace("```json", "");
           _mdText = _mdText.replace("```", "");
+					// 使用正则表达式匹配JSON数组
+					const regex = /\[\s*{[^]*}\s*\]/;
+					const match = _mdText.match(regex);
+					let _result = match[0]
           this.source.close();
           this.chatLoading = false;
           this.chatList.find(i => i.uid == _uid).aiContent = JSON.parse(
-            _mdText
+            _result
           );
           this.chatList.find(i => i.uid == _uid).isalltext = true;
           this.chatList.find(i => i.uid == _uid).isShowSynchronization = true;
@@ -1538,10 +1542,11 @@ Instruction: Based on the context, follow "Format example", write content
         .then(res => {
 					console.log(res)
 					let _data = res.data.FunctionResponse.message;
-					console.log(_data);
 					_data = _data.replaceAll("```json", "").replaceAll("```", "");
+					const match = _data.match(/\[\s*{[^]*}\s*\]/)
 					console.log(_data)
-					this.chatList.find(i => i.uid == _uuid).aiContent =JSON.parse(_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;