|
|
@@ -1,35 +1,83 @@
|
|
1
|
1
|
import commonModel from '../model/commonModel.js';
|
|
2
|
2
|
import fs from 'fs';
|
|
3
|
3
|
import { stringUtils } from '../util/stringClass.js';
|
|
|
4
|
+import aiController from '../api/yjbdc/aiController.js';
|
|
4
|
5
|
|
|
5
|
6
|
async function runScript(){
|
|
6
|
7
|
try {
|
|
7
|
8
|
|
|
8
|
|
- const sql="SELECT * FROM kylx365_db.Words;"
|
|
|
9
|
+ //按照高频单词的使用频率排序,列出所有单词
|
|
|
10
|
+ const sql="select ID,Word from Words where BookID=110 order by ID;"
|
|
9
|
11
|
let list = await commonModel.RunSql(null,sql);
|
|
10
|
12
|
let count=list.length;
|
|
|
13
|
+
|
|
|
14
|
+ const start=40;
|
|
11
|
15
|
//count=10;
|
|
12
|
|
- for(let i=0;i<count;i++){
|
|
|
16
|
+
|
|
|
17
|
+ // 添加延时函数,确保每分钟只发送9次请求(约每6.67秒一次请求)
|
|
|
18
|
+ const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
|
19
|
+ const requestDelay = 7000; // 7秒,确保每分钟最多9次请求
|
|
|
20
|
+
|
|
|
21
|
+ for(let i=start;i<count;i++){
|
|
13
|
22
|
let item=list[i];
|
|
14
|
23
|
|
|
15
|
|
- let str=item.Translate;
|
|
16
|
|
- str=stringUtils.ReplaceAllString(str,",",",");
|
|
17
|
|
- if (str!=item.Translate){
|
|
18
|
|
- console.log(str);
|
|
19
|
|
- let sql2="update Words set Translate='"+str+"' where ID="+item.ID;
|
|
20
|
|
- await commonModel.RunSql(null,sql2);
|
|
21
|
|
- }
|
|
22
|
|
- console.log( i +"/"+ list.length);
|
|
|
24
|
+ //获得单词
|
|
|
25
|
+ const word=item.Word;
|
|
23
|
26
|
|
|
|
27
|
+ let content={
|
|
|
28
|
+ "instruction": "用单词"+word+"生成例句,中国学生学习英文使用",
|
|
|
29
|
+ "requirements": [
|
|
|
30
|
+ "判断单词在CEFR的最低级别,比如experience是B1",
|
|
|
31
|
+ "用单词最常用的含义生成最低级别到C1各两句例句,比如experience生成B1、B2、C1各两句",
|
|
|
32
|
+ "单词允许类似过去式、复数等变形",
|
|
|
33
|
+ "提供例句翻译",
|
|
|
34
|
+ ],
|
|
|
35
|
+ "output_format":{
|
|
|
36
|
+ "word":"单词",
|
|
|
37
|
+ "CEFR_Level":"A1",
|
|
|
38
|
+ "Sentences": [
|
|
|
39
|
+ {
|
|
|
40
|
+ "Sentence":"句子1",
|
|
|
41
|
+ "Translate": "翻译1",
|
|
|
42
|
+ "Level": "A1",
|
|
|
43
|
+ },{
|
|
|
44
|
+ "Sentence":"句子2",
|
|
|
45
|
+ "Translate": "翻译2",
|
|
|
46
|
+ "Level": "A2",
|
|
|
47
|
+ },
|
|
|
48
|
+ ]
|
|
|
49
|
+ }
|
|
|
50
|
+ };
|
|
|
51
|
+ content=JSON.stringify(content);
|
|
|
52
|
+
|
|
|
53
|
+ const aiProvider="llama-4-maverick-17b-128e-instruct";
|
|
|
54
|
+
|
|
|
55
|
+ //生成例句
|
|
|
56
|
+ let result = await aiController.generateArticle(content, aiProvider);
|
|
|
57
|
+ //console.log(result);
|
|
|
58
|
+ let sql2="update Words set ExampleSentence=? where ID="+item.ID+";";
|
|
|
59
|
+ await commonModel.RunSql(result,sql2);
|
|
|
60
|
+
|
|
|
61
|
+ console.log( i +"/"+ list.length);
|
|
|
62
|
+
|
|
|
63
|
+ // 在每次请求后添加延时,除非是最后一个请求
|
|
|
64
|
+ if (i < count - 1) {
|
|
|
65
|
+ console.log(`等待 ${requestDelay/1000} 秒后继续下一个请求...`);
|
|
|
66
|
+ await delay(requestDelay);
|
|
|
67
|
+ }
|
|
24
|
68
|
}
|
|
25
|
69
|
|
|
26
|
|
-
|
|
27
|
70
|
console.log("完成");
|
|
28
|
71
|
} catch (error) {
|
|
29
|
72
|
console.error('Error executing script:', error);
|
|
30
|
73
|
}
|
|
31
|
74
|
}
|
|
32
|
75
|
|
|
|
76
|
+// 处理Promise并添加错误捕获
|
|
|
77
|
+runScript().catch(error => {
|
|
|
78
|
+ console.error('Error in runScript:', error);
|
|
|
79
|
+});
|
|
|
80
|
+
|
|
33
|
81
|
////批量处理加资料的数据
|
|
34
|
82
|
// async function runScript(){
|
|
35
|
83
|
// try {
|
|
|
@@ -66,7 +114,3 @@ async function runScript(){
|
|
66
|
114
|
// }
|
|
67
|
115
|
// }
|
|
68
|
116
|
|
|
69
|
|
-// 处理Promise并添加错误捕获
|
|
70
|
|
-runScript().catch(error => {
|
|
71
|
|
- console.error('Error in runScript:', error);
|
|
72
|
|
-});
|