Browse Source

fix: random

Carson 1 year ago
parent
commit
71e87b0b9d
1 changed files with 71 additions and 32 deletions
  1. 71 32
      src/components/pages/classroomObservation/components/chatArea.vue

+ 71 - 32
src/components/pages/classroomObservation/components/chatArea.vue

@@ -1,5 +1,5 @@
 <template>
 <template>
-  <div class="chatArea" v-loading="loading" :element-loading-text="loadingText">
+  <div class="chatArea" v-loading="loading">
     <div class="m-operation">
     <div class="m-operation">
       <div>实时转录</div>
       <div>实时转录</div>
       <div>{{ createTime }}</div>
       <div>{{ createTime }}</div>
@@ -60,7 +60,7 @@
         @change="changeEditor"
         @change="changeEditor"
       >
       >
         <el-button
         <el-button
-          style="position: absolute; bottom: 70px; right: 20px; z-index: 10002"
+          style="position: absolute; bottom: 20px; right: 100px; z-index: 10002"
           type="primary"
           type="primary"
           @click.stop="generateActionTypesMap"
           @click.stop="generateActionTypesMap"
           >自动编码</el-button
           >自动编码</el-button
@@ -378,6 +378,17 @@
       </div>
       </div>
       <!-- <el-progress style="width:80%" :text-inside="true" :stroke-width="24" :percentage="progressData.value"></el-progress> -->
       <!-- <el-progress style="width:80%" :text-inside="true" :stroke-width="24" :percentage="progressData.value"></el-progress> -->
     </div>
     </div>
+    <div class="chatAreaLoading" v-else-if="actionTypeLoading">
+      <div class="cal_box" :style="{ height: '300px' }">
+        <div
+          :style="{ width: '100%', height: '100px' }"
+          v-loading="true"
+          :element-loading-text="actionTypeLoadingText"
+        ></div>
+        <el-button @click="stopGenerateActionTypes">停止</el-button>
+      </div>
+      <!-- <el-progress style="width:80%" :text-inside="true" :stroke-width="24" :percentage="progressData.value"></el-progress> -->
+    </div>
   </div>
   </div>
 </template>
 </template>
 
 
@@ -408,6 +419,23 @@ import _ from "lodash";
 // 	console.log('当前录音的总数据([DataView, DataView...])', params.data);
 // 	console.log('当前录音的总数据([DataView, DataView...])', params.data);
 // 	console.log('--------------END---------------')
 // 	console.log('--------------END---------------')
 // };
 // };
+const OPTIONS_GROUP = {
+  default: [
+    "老师讲课",
+    "老师提问或点名",
+    "老师板书或操作",
+    "老师评价或反馈",
+    "老师其他",
+    "学生发言",
+    "学生小组活动",
+    "学生自主学习",
+    "学生汇报分享",
+    "学生其他",
+  ],
+};
+const ATTENTION_GROUP = {
+  default: "先根据说话人角色判断,再在对应角色的选项中选择选项",
+};
 
 
 // 自定义指令,用于处理点击外部区域的事件
 // 自定义指令,用于处理点击外部区域的事件
 const clickOutside = {
 const clickOutside = {
@@ -503,7 +531,6 @@ export default {
       languageRadio: 2, //设置选择语言
       languageRadio: 2, //设置选择语言
       languageShow: false, //控制显示
       languageShow: false, //控制显示
       loading: false,
       loading: false,
-      loadingText: undefined,
       chatLoading: false,
       chatLoading: false,
       transcriptionLoading: false,
       transcriptionLoading: false,
       uploadFileLoading: false,
       uploadFileLoading: false,
@@ -576,6 +603,8 @@ export default {
       },
       },
       chatList: [],
       chatList: [],
       actionTypesMap: {},
       actionTypesMap: {},
+      actionTypeLoading: false,
+      actionTypeLoadingText: "",
     };
     };
   },
   },
   computed: {
   computed: {
@@ -598,16 +627,14 @@ export default {
     },
     },
     tid: {
     tid: {
       async handler(tid) {
       async handler(tid) {
-        console.log("tid handle: ", tid);
         if (!tid) {
         if (!tid) {
           this.actionTypesMap = undefined;
           this.actionTypesMap = undefined;
           return;
           return;
         }
         }
         this.actionTypesMap = await this.loadActionTypesMap();
         this.actionTypesMap = await this.loadActionTypesMap();
-        console.log("result: ", this.actionTypesMap);
         if (!this.actionTypesMap) {
         if (!this.actionTypesMap) {
           const res = await this.insertActionTypes();
           const res = await this.insertActionTypes();
-          console.log("res: ", res);
+          this.actionTypesMap = await this.loadActionTypesMap();
         }
         }
       },
       },
       immediate: true,
       immediate: true,
@@ -2136,7 +2163,7 @@ ${JSON.stringify(_list)}
 				</table>
 				</table>
 				`;
 				`;
       }
       }
-      console.log(_content);
+      // console.log(_content);
       this.editorBarData = { ..._editorBarData, content: _content };
       this.editorBarData = { ..._editorBarData, content: _content };
     },
     },
     // 获取对话记录
     // 获取对话记录
@@ -2271,18 +2298,8 @@ ${JSON.stringify(_list)}
       const key = "default";
       const key = "default";
       const appToken = "app-zOMxBqyEKoJSvW10e5SS0kgj";
       const appToken = "app-zOMxBqyEKoJSvW10e5SS0kgj";
       // the default options
       // the default options
-      const options = [
-        "老师讲课",
-        "老师提问或点名",
-        "老师板书或操作",
-        "老师评价或反馈",
-        "老师其他",
-        "学生发言",
-        "学生小组活动",
-        "学生自主学习",
-        "学生汇报分享",
-        "学生其他",
-      ];
+      const options = OPTIONS_GROUP[key];
+      const attention = ATTENTION_GROUP[key];
       const config = {
       const config = {
         headers: {
         headers: {
           Authorization: `Bearer ${appToken}`,
           Authorization: `Bearer ${appToken}`,
@@ -2297,33 +2314,44 @@ ${JSON.stringify(_list)}
         this.$notify.info("没有可编码的内容");
         this.$notify.info("没有可编码的内容");
         return;
         return;
       }
       }
-      tableRows.forEach((i) => {
-        while (i.cells.length >= 7) {
-          i.removeChild(i.lastElementChild);
-        }
+      this.actionTypeLoading = true;
+      this.generateActionTypesCtrl = new AbortController();
+      const signal = this.generateActionTypesCtrl.signal;
+      await new Promise((resolve) => {
+        this.$nextTick(resolve);
       });
       });
-      this.loading = true;
-      this.loadingText = `0/${tableRows.length}`;
       try {
       try {
-        const chunkSize = 200;
+        tableRows.forEach((i) => {
+          while (i.cells.length >= 7) {
+            i.removeChild(i.lastElementChild);
+          }
+        });
+        this.actionTypeLoadingText = `( 0/${tableRows.length} )`;
+        // large chunk size will cause token limit and slower
+        const chunkSize = 30;
         this.actionTypesMap.jsonData[key] = Array.from({ length: tableRows.length });
         this.actionTypesMap.jsonData[key] = Array.from({ length: tableRows.length });
         // action type fetch by every { chunkSize } rows
         // action type fetch by every { chunkSize } rows
         for (const [index, rows] of _.chunk(tableRows, chunkSize).entries()) {
         for (const [index, rows] of _.chunk(tableRows, chunkSize).entries()) {
           const res = await fetch("https://dify.cocorobo.cn/v1/workflows/run", {
           const res = await fetch("https://dify.cocorobo.cn/v1/workflows/run", {
+            signal,
             method: "POST",
             method: "POST",
             body: JSON.stringify({
             body: JSON.stringify({
               inputs: {
               inputs: {
                 // PERF better to just include `role` and `content` to minimize token cost
                 // PERF better to just include `role` and `content` to minimize token cost
-                rows: rows
-                  .map((r) => `${r.cells[3].textContent}\t${r.cells[5].textContent}`)
-                  .join("\n"),
+                rows: JSON.stringify(
+                  rows.map((r) => [r.cells[3].textContent, r.cells[5].textContent])
+                ),
                 options: options.join(","),
                 options: options.join(","),
+                attention,
               },
               },
               response_mode: "blocking",
               response_mode: "blocking",
               user: this.userId,
               user: this.userId,
             }),
             }),
             ...config,
             ...config,
           }).then((res) => res.json());
           }).then((res) => res.json());
+          if (signal.aborted) {
+            return;
+          }
           const error = _.get(res, ["data", "error"], null);
           const error = _.get(res, ["data", "error"], null);
           if (error) {
           if (error) {
             this.$notify.error(error);
             this.$notify.error(error);
@@ -2339,16 +2367,27 @@ ${JSON.stringify(_list)}
             transcriptionData: this.transcriptionData.content,
             transcriptionData: this.transcriptionData.content,
             editorBarData: this.editorBarData,
             editorBarData: this.editorBarData,
           });
           });
-          this.loadingText = `${index * chunkSize + rows.length}/${tableRows.length}`;
+          this.actionTypeLoadingText = `( ${index * chunkSize + rows.length}/${
+            tableRows.length
+          } )`;
         }
         }
       } catch (err) {
       } catch (err) {
+        if (err.name === "AbortError") {
+          return;
+        }
         console.error(err);
         console.error(err);
         this.$notify.error(err);
         this.$notify.error(err);
       } finally {
       } finally {
-        this.loading = false;
-        this.loadingText = undefined;
+        this.actionTypeLoading = false;
+        this.actionTypeLoadingText = "";
+        this.generateActionTypesCtrl = undefined;
       }
       }
     },
     },
+    stopGenerateActionTypes() {
+      console.log("stopGenerateActionTypes");
+      this.generateActionTypesCtrl && this.generateActionTypesCtrl.abort();
+      this.generateActionTypesCtrl = undefined;
+    },
   },
   },
   mounted() {},
   mounted() {},
 };
 };