Parcourir la source

教师管理-智能助手-猜你想问-修改

lzw il y a 4 mois
Parent
commit
de5399715c
1 fichiers modifiés avec 228 ajouts et 90 suppressions
  1. 228 90
      src/components/pages/test/checkAi/aiLeader.vue

+ 228 - 90
src/components/pages/test/checkAi/aiLeader.vue

@@ -9,7 +9,7 @@
           </div>
         </div>
         <div style="margin-top:20px;margin-bottom:20px ; margin-right: auto;"
-          v-if="item.aiContent || item.loading || fileList.length == 0">
+          v-if="(item.aiContent || item.loading || fileList.length == 0) && item.content!==0">
           <div class="role">
             <img :src="item.fileid
               ? item.fileid
@@ -28,7 +28,7 @@
             <img src="../../../../assets/icon/course/pasete.png" @click="onCopy(item.aiContent)" />
           </div>
         </div>
-        <div style="margin-top:20px;margin-bottom:20px ; margin-right: auto;" v-if="isShow">
+        <div style="margin-top:20px;margin-bottom:20px ; margin-right: auto;" v-if="item.content === 0">
           <div class="role">
             <img :src="item.fileid
               ? item.fileid
@@ -43,8 +43,8 @@
               <img :src="require('../../../../assets/icon/course/idea.png')" />
               <span>猜你想问:</span>
             </div>
-            <div class="guess_item" v-for="item in wangData" :key="item.index" @click="copyText(item.label)">
-              {{ item.label}}
+            <div class="guess_item" v-for="item in item.aiContent" :key="item.index" @click="copyText(item.label)">
+              {{ item.label }}
             </div>
             <span class="createTime" v-text="item.createtime"></span>
           </div>
@@ -478,8 +478,9 @@ export default {
       copyWorksArray: null,
       stopTalkToken: false,
       getWangLoading: false,
-      wangData:[],
-      canUseWangData: true
+      wangData: [],
+      canUseWangData: true,
+      hasGeneratedGuess: false
     };
   },
   watch: {
@@ -499,7 +500,8 @@ export default {
           // this.setJson(newValue)
         }
       }
-    }
+    },
+
   },
   methods: {
     delFileList(index) {
@@ -571,9 +573,9 @@ export default {
       this.getData(this.cid)
       this.guessAskJson()
       this.addChat()
-
+      this.dialogTableVisible = false;
       // this.getChatList()
-      
+
 
     },
     handleClose(done) {
@@ -582,6 +584,7 @@ export default {
     triggerFileInput() {
       this.btnactive = 2
       this.isShow = true;
+      this.guessAskJson()
       this.$refs.fileInput.click();
     },
     // 处理文件选择
@@ -593,33 +596,33 @@ export default {
       }
     },
     addChat() {
-            return new Promise((resolve) => {
-                const names = this.menuList.map(item => item.name).join(', ');
-                console.log(names);
-                console.log(">",courseId);
-                
-                let params = [{
-                    uid: this.userid,
-                    name:names,
-                    courseId:this.cid
-                }];
-                this.ajax
-                    .post(this.$store.state.api + "addChat", params)
-                    .then(res => { 
-                        console.log("res",res);
-
-                        
-                    })
-                    .catch((err) => {
-                        resolve();
-                        console.error(err);
-                    })
-            })
+      return new Promise((resolve) => {
+        const names = this.menuList.map(item => item.name).join(', ');
+        console.log(names);
+        console.log(">", courseId);
+
+        let params = [{
+          uid: this.userid,
+          name: names,
+          courseId: this.cid
+        }];
+        this.ajax
+          .post(this.$store.state.api + "addChat", params)
+          .then(res => {
+            console.log("res", res);
+
+
+          })
+          .catch((err) => {
+            resolve();
+            console.error(err);
+          })
+      })
     },
     guessAskJson() {
       const names = this.worksArray.map(item => item.name).join(', ');
       console.log("获取猜你想搜", names);
-      let _uuid = uuidv4();
+      let _uid = uuidv4();
       this.getWangLoading = true;
       this.canUseWangData = false;
       this.wangData = "";
@@ -634,8 +637,23 @@ export default {
         file_ids: this.fileId,
         model: "gpt-4o-2024-08-06"
       };
+      this.array.push({
+        loading: false,
+        role: "user",
+        content: 0,
+        uid: _uid,
+        AI: "AI",
+        aiContent: "",
+        oldContent: "",
+        isShowSynchronization: false,
+        filename: "",
+        index: this.array.length,
+        is_mind_map: false,
+        fileid: "",
+        createtime: new Date().toLocaleString().replaceAll("/", "-")
+      });
       this.text = "";
-      this.dialogTableVisible = false;
+      
       this.ajax
         // .post("https://gpt4.cocorobo.cn/chat", params)
         // .post("https://claude3.cocorobo.cn/chat", params)
@@ -650,20 +668,9 @@ export default {
           // console.log("match",match);
           this.wangData = JSON.parse(match[0]);
           this.canUseWangData = true;
-          this.getWangLoading= false;
-          
-          console.log("wangData",this.wangData);
-          
-          // console.log(_data);
-
-          // 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;
+          this.getWangLoading = false;
+          console.log("wangData", this.wangData);
+          this.array.find(i => i.uid == _uid).aiContent = JSON.parse(match[0]);
         })
         .catch(e => {
           this.chatLoading = false;
@@ -673,28 +680,7 @@ export default {
         });
       // this.getWAntSearchContent(_uuid);
     },
-    // guessAsk(){
-    //   const names = this.worksArray.map(item => item.name).join(', ');
-    //   console.log(this.wangData);
-    //   const result = this.wangData.map(item => item.label).join('');
-    //   console.log("result",result);
-
-    //   let params = {
-    //     userId: this.userid,
-    //     userName: this.username,
-    //     groupId: "602def61-005d-11ee-91d8-005056b8q12w",
-    //     answer: result,
-    //     problem: "",
-    //     file_id: this.fileId,
-    //     alltext: result,
-    //     type: "chat",
-    //     filename: names,
-    //     session_name: `${this.formId}-testSmarter`
-    //   };
-    //   this.ajax
-    //     .post("https://gpt4.cocorobo.cn/insert_chat", params)
-    //     .then(res => { });
-    // },
+    
     beforeUploadInfo2(event, type, tindex) {
       // const loading = this.openLoading();
       let file = "";
@@ -1524,7 +1510,7 @@ export default {
           }
         });
         this.faloading = true;
-        this.isShow = false;
+
         console.log("isShow", this.isShow);
         if (_atRoleList.length > 0) {
           //有@角色
@@ -2383,28 +2369,180 @@ export default {
       this.showRoleList = false;
     },
     copyText(text) {
-      // 使用 Clipboard API 来复制内容
-      if (navigator.clipboard) {
-        navigator.clipboard.writeText(text).then(() => {
-          this.$message({
-            message: "复制成功",
-            type: "success"
-          });
-        }).catch(err => {
-          console.error("Error copying text: ", err);
+      let message = text;
+      if (text) {
+        let msg = ``;
+        if (this.answerArray.length) {
+          // msg += `
+          // ## 表单资料
+          // ${JSON.stringify(this.answerArray)}
+          // `;
+
+          // msg += `
+          // ## 要求
+          // 根据<参考资料>中的内容实现以下要求:${this.courseText}
+          // `;
+          msg += `## 要求
+根据上传文件中的内容实现以下要求:${text}`;
+          message = msg;
+        }
+        // 这里处理@的角色
+        let _atRoleList = [];
+        let _roleList = [...this.roleList, ...this.publicRoleList];
+        _roleList.forEach(i => {
+          if (message.indexOf(`@${i.assistantName}`) != -1) {
+            _atRoleList.push(i);
+          }
         });
-      } else {
-        // 如果 Clipboard API 不支持,使用 document.execCommand 方法
-        const textArea = document.createElement("textarea");
-        textArea.value = text;
-        document.body.appendChild(textArea);
-        textArea.select();
-        document.execCommand("copy");
-        document.body.removeChild(textArea);
-        this.$message({
-            message: "复制成功",
-            type: "success"
+        this.faloading = true;
+
+        console.log("isShow", this.isShow);
+        if (_atRoleList.length > 0) {
+          //有@角色
+          let _replaceText = `Role: 你是数据检索大师,可以利用file_search的方式完整的去分析文件内容 Language: Please use the same language as the user requirement, if the user speaks Chinese, the specific text of your answer should also be in Chinese.\n${message}`;
+          let _htmlText = message;
+          _atRoleList.forEach(_i => {
+            _replaceText = _replaceText.replaceAll(`@${_i.assistantName}`, ``);
+            _htmlText = _htmlText.replaceAll(
+              `@${_i.assistantName}`,
+              `<span class='aite-name'>@${_i.assistantName}</span>`
+            );
           });
+
+          _atRoleList.forEach((_item, _index) => {
+            const _uid = uuidv4();
+            if (_index == 0) {
+              this.array.push({
+                loading: true,
+                role: "user",
+                content: _htmlText,
+                uid: _uid,
+                AI: "AI",
+                aiContent: "",
+                oldContent: "",
+                isShowSynchronization: false,
+                filename: _item.assistantName,
+                index: this.array.length,
+                is_mind_map: false,
+                fileid: _item.headUrl,
+                createtime: new Date().toLocaleString().replaceAll("/", "-")
+              });
+            } else {
+              this.array.push({
+                loading: true,
+                role: "user",
+                content: "",
+                uid: _uid,
+                AI: "AI",
+                aiContent: "",
+                oldContent: "",
+                isShowSynchronization: false,
+                filename: _item.assistantName,
+                index: this.array.length,
+                is_mind_map: false,
+                fileid: _item.headUrl,
+                createtime: new Date().toLocaleString().replaceAll("/", "-")
+              });
+            }
+            this.$nextTick(() => {
+              this.$refs.chatDialog.scrollTop = this.$refs.chatDialog.scrollHeight;
+            });
+
+            let params = {
+              assistant_id: _item.assistant_id,
+              userId: this.userid,
+              message: _replaceText,
+              session_name: `${this.courseId}-${this.userid}-test`,
+              uid: _uid,
+              file_ids: this.fileId ? this.fileId : [],
+              // model: "gpt-4o-mini"
+              model: "qwen-plus"
+            };
+
+            this.ajax
+              .post("https://gpt4.cocorobo.cn/ai_agent_park_chat_new", params)
+              .then(res => {
+                if (
+                  converter(res.data.FunctionResponse.result) ==
+                  converter("发送成功")
+
+                ) {
+                } else {
+                  this.$message.warning(res.data.FunctionResponse.result);
+                }
+              })
+              .catch(err => {
+                console.log(err);
+              });
+            // this.getAtAuContent(_uid);
+            this.saveUid = _uid;
+          });
+          console.log("我是array", this.array);
+
+
+        } else {
+          let _uuid = uuidv4();
+          this.array.push({
+            role: "user",
+            content: `${text}`,
+            uid: _uuid,
+            AI: "AI",
+            aiContent: "",
+            oldContent: "",
+            isShowSynchronization: false,
+            filename: "",
+            index: this.array.length,
+            is_mind_map: false,
+            createtime: new Date().toLocaleString().replaceAll("/", "-"),
+            loading: true
+          });
+
+          let params = {
+            prompt: message,
+            messages: [],
+            file: this.fileList ? this.fileList : []
+          };
+          this.stopTalkToken = this.ajax.setCancelSource()
+          this.$nextTick(() => {
+            this.$refs.chatDialog.scrollTop = this.$refs.chatDialog.scrollHeight;
+          });
+
+          this.saveUid = _uuid;
+          this.ajax
+            // .post("https://gpt4.cocorobo.cn/ai_agent_park_chat_new", params)
+            .post("https://gpt4.cocorobo.cn/csvaimessage", params, this.stopTalkToken)
+            .then(res => {
+              // if (
+              //   converter(res.data.FunctionResponse.result) ==
+              //   converter("发送成功")
+              // ) {
+              // } else {
+              //   this.$message.warning(res.data.FunctionResponse.result);
+              // }
+              let data = res.data.FunctionResponse;
+              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.stopTalkToken = null;
+              this.faloading = false;
+              this.$nextTick(() => {
+                this.$refs.chatDialog.scrollTop = this.$refs.chatDialog.scrollHeight;
+              });
+              // if (this.courseId) {
+              // this.insertChat(_uuid);
+              // }
+            })
+            .catch(err => {
+              console.log(err);
+              this.faloading = false;
+              this.stopTalkToken = null;
+            });
+          // this.getAtAuContent(_uuid);
+          // this.saveUid = _uuid;
+        }
       }
     },
     onCopy(content) {