chengjie 4 달 전
부모
커밋
6b5e767ef1
3개의 변경된 파일66개의 추가작업 그리고 75개의 파일을 삭제
  1. 0 2
      src/api/yjbdc/yjbdcController.js
  2. 3 1
      src/test/build.test.js
  3. 63 72
      src/test/build.test2.js

+ 0 - 2
src/api/yjbdc/yjbdcController.js

@@ -18,8 +18,6 @@ import tencentcloud from 'tencentcloud-sdk-nodejs-ocr';
18 18
 const OcrClient = tencentcloud.ocr.v20181119.Client;
19 19
 const ONE_DAY_MAX_BUILD_COUNT=12;//一天最大生成数
20 20
 
21
-
22
-
23 21
 //AI生成文章
24 22
 export async function GenerateArticle(ctx) {
25 23
 

+ 3 - 1
src/test/build.test.js

@@ -7,7 +7,7 @@ async function runScript(){
7 7
     try {
8 8
         
9 9
         //按照高频单词的使用频率排序,列出所有单词
10
-        const sql="select * from Words where BookID=110 and ExampleSentence is null order by ID;"
10
+        const sql="select * from Words where BookID=110 and (ExampleSentence is null or ExampleSentence='') order by ID;"
11 11
         let list = await commonModel.RunSql(null,sql);
12 12
         let count=list.length;
13 13
 
@@ -29,6 +29,7 @@ async function runScript(){
29 29
                     "用单词最常用的含义生成最低级别到C1各两句例句,比如experience生成B1、B2、C1各两句",
30 30
                     "单词允许类似过去式、复数等变形",
31 31
                     "提供例句翻译",
32
+                    "格式要求是JSON格式,完全遵循output_format,另外生成不要有重复“\"”"
32 33
                 ],
33 34
                 "output_format":{
34 35
                     "word":"单词",
@@ -52,6 +53,7 @@ async function runScript(){
52 53
 
53 54
             //生成例句
54 55
             let result = await aiController.generateArticle(content, aiProvider);
56
+            
55 57
             console.log(result); 
56 58
             let sql2="update Words set ExampleSentence=? where ID="+item.ID+";";
57 59
             await commonModel.RunSql(result,sql2);

+ 63 - 72
src/test/build.test2.js

@@ -4,105 +4,96 @@ import { stringUtils } from '../util/stringClass.js';
4 4
 import aiController from '../api/yjbdc/aiController.js';
5 5
 
6 6
 async function runScript(){
7
+    let id,word;
7 8
     try {
8 9
         
9
-        const sql="select * from Words where BookID=110 and Soundmark is null order by ID;"
10
+        const sql="select * from Words where BookID=110 and ExampleSentence is not null order by ID;;"
10 11
         let list = await commonModel.RunSql(null,sql);
11 12
         let count=list.length;
12 13
 
13
-        const start=0;
14
+        const start=8045;
15
+        //count=10;
14 16
         // 添加延时函数,确保每分钟只发送9次请求(约每6.67秒一次请求)
15
-        const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
16
-        const requestDelay = 300; // 7秒,确保每分钟最多9次请求
17
+        // const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
18
+        // const requestDelay = 300; // 7秒,确保每分钟最多9次请求
17 19
         
18 20
         for(let i=start;i<count;i++){
19 21
             let item=list[i];
20 22
 
23
+            id=item.ID;
21 24
             //获得单词
22
-            const word=item.Word;
25
+            word=item.Word;
26
+            let exampleSentence=item.ExampleSentence;
27
+            if (exampleSentence){
28
+                exampleSentence=JSON.parse(exampleSentence);
29
+                let sql2="update Words set ExampleSentence=?,Level='"+exampleSentence.CEFR_Level+"' where BookID<>110 and BookID not in (141,142,143,144,145,146,161,162,163,164,165,166,167,168) and ExampleSentence is null and Word='"+word+"';";
30
+                //console.log(sql2);
31
+                await commonModel.RunSql(item.ExampleSentence,sql2);
32
+            }
33
+            else{
34
+                console.log( word +" 空");
35
+            }
36
+            console.log( i +"/"+ list.length);
37
+            
38
+            // 在每次请求后添加延时,除非是最后一个请求
39
+            // if (i < count - 1) {
40
+            //     console.log(`等待 ${requestDelay/1000} 秒后继续下一个请求...`);
41
+            //     await delay(requestDelay);
42
+            // }
43
+        }
44
+        
45
+        console.log("完成");
46
+    } catch (error) {
47
+        console.log(id + " " +word);
48
+        console.error('Error executing script:', error);
49
+    }
50
+}
23 51
 
24
-            let content={
25
-                "instruction": "提供单词"+word+"音标",
26
-                "output_format":{
27
-                    "Soundmark":"[音标]",
28
-                }
29
-            };
30 52
 
31
-            content=JSON.stringify(content);
32 53
 
33
-            const aiProvider="doubao-1-5-pro-32k-250115";
34 54
 
35
-            //生成例句
36
-            let result = await aiController.generateArticle(content, aiProvider);
55
+async function runScript2(){
56
+    let id,word;
57
+    try {
58
+        
59
+        const sql="SELECT * FROM kylx365_db.Words where BookID=110 and ExampleSentence like '{\"word\"%}]}%例句%';"
60
+        let list = await commonModel.RunSql(null,sql);
61
+        let count=list.length;
37 62
 
38
-            result=JSON.parse(result);
39
-            //console.log(result); 
63
+        const start=0;
64
+        //count=10;
65
+        
66
+        for(let i=start;i<count;i++){
67
+            let item=list[i];
40 68
 
41
-            let soundmark=result.Soundmark;
42
-            //console.log(soundmark); 
69
+            id=item.ID;
70
+            //获得单词
71
+            word=item.Word;
72
+            let exampleSentence=item.ExampleSentence;
73
+
74
+            exampleSentence=exampleSentence.substr(exampleSentence.lastIndexOf("{\"word"),exampleSentence.lastIndexOf("}]}")+3);
43 75
 
44
-            soundmark=stringUtils.ReplaceAllString(soundmark,"'","ˈ");
45
-            soundmark=stringUtils.ReplaceAllString(soundmark,"\"","");
46
-            if (soundmark.substr(0,1)!="[")
47
-                soundmark="["+soundmark+"]";
76
+            console.log(exampleSentence);
48 77
             
49
-            console.log(word +" "+soundmark); 
50
-            let sql2="update Words set Soundmark=? where ID="+item.ID+";";
51
-            await commonModel.RunSql(soundmark,sql2);
78
+            let sql2="update Words set ExampleSentence=? where ID="+id+";";
79
+            //console.log(sql2);
80
+            await commonModel.RunSql(exampleSentence,sql2);
52 81
             
53 82
             console.log( i +"/"+ list.length);
54
-            
55
-            // 在每次请求后添加延时,除非是最后一个请求
56
-            // if (i < count - 1) {
57
-            //     console.log(`等待 ${requestDelay/1000} 秒后继续下一个请求...`);
58
-            //     await delay(requestDelay);
59
-            // }
60 83
         }
61 84
         
62 85
         console.log("完成");
63 86
     } catch (error) {
87
+        console.log(id + " " +word);
64 88
         console.error('Error executing script:', error);
65 89
     }
66 90
 }
67 91
 
68 92
 // 处理Promise并添加错误捕获
69
-runScript().catch(error => {
70
-    console.error('Error in runScript:', error);
71
-});
72
-
73
-////批量处理加资料的数据
74
-// async function runScript(){
75
-//     try {
76
-//         const sql="select ID from MiaoguoLiteracy order by ID;"
77
-//         let list = await commonModel.RunSql(null,sql);
78
-//         for(let i=0;i<list.length;i++){
79
-//             if (i % 1000 == 0)
80
-//                 console.log("i:"+i+" ID:"+list[i].ID
81
-//             let item =await commonModel.RunSql(null,"select * from MiaoguoLiteracy where ID="+list[i].ID+";"
82
-//             let json;
83
-//             try {
84
-//                 json = JSON.parse(item[0].JSONString
85
-//             } catch (parseError) {
86
-//                 console.error('JSON Parse Error at ID:', list[i].ID);
87
-//                 console.error('Error details:', parseError);
88
-//                 continue;
89
-//             }
90
-//             if (json && json.CHN && json.CHN.BiShunArr && json.CHN.BiShunArr.length>0){
91
-//                 console.log(i+" "+json.CHN.HanZi);
92
-                
93
-//                 delete json.CHN.BiShunArr;
94
-//                 let obj={};
95
-//                 obj.ID=list[i].ID;
96
-//                 obj.JSONString=JSON.stringify(json);
97
-
98
-//                 await commonModel.RunSql(obj,"update MiaoguoLiteracy set ? where ID="+list[i].ID+";"
99
-//             }
100
-//             //console.log(json);
101
-//             //console.log(item.length);
102
-//         }
103
-//         console.log("完成"
104
-//     } catch (error) {
105
-//         console.error('Error executing script:', error);
106
-//     }
107
-// }
108
-
93
+if (1==1){
94
+    runScript().catch(error => {
95
+        console.error('Error in runScript:', error);
96
+    });
97
+}
98
+else
99
+    runScript2();