@3-/aiapi 0.1.79 → 0.1.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/check/SEARCH.js +1 -1
- package/fmt.js +2 -2
- package/package.json +1 -1
- package/partition.js +5 -4
- package/researchFmt.js +3 -3
- package/seg.js +52 -22
package/check/SEARCH.js
CHANGED
package/fmt.js
CHANGED
|
@@ -4,8 +4,8 @@ import fmtJson from './fmtJson.js';
|
|
|
4
4
|
import partition from './partition.js';
|
|
5
5
|
|
|
6
6
|
export default async(chat, txt) => {
|
|
7
|
-
var pli
|
|
8
|
-
pli = (await partition(chat, txt));
|
|
7
|
+
var pli, 题;
|
|
8
|
+
[题, pli] = (await partition(chat, txt));
|
|
9
9
|
if (!pli.length) {
|
|
10
10
|
return '';
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@3-/aiapi","version":"0.1.
|
|
1
|
+
{"name":"@3-/aiapi","version":"0.1.80","repository":{"type":"git","url":"git+https://atomgit.com/i18n/lib.git"},"homepage":"https://atomgit.com/i18n/lib/tree/dev/aiapi","author":"i18n.site@gmail.com","license":"MulanPSL-2.0","exports":{".":"./lib.js","./*":"./*"},"files":["./*"],"devDependencies":{"@3-/read":"^0.1.4"},"scripts":{},"type":"module","dependencies":{"@3-/retry":"^0.0.2","@3-/rm_cn_space":"^0.1.1","@3-/sleep":"^0.0.4","@3-/txt_li":"^0.1.5","@3-/utf8":"^0.0.4","lodash-es":"^4.17.21"}}
|
package/partition.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import seg from "./seg.js";
|
|
1
|
+
import { default as seg, segWithTitle } from "./seg.js";
|
|
2
2
|
import txtLi from "@3-/txt_li";
|
|
3
3
|
import rmCnSpace from "@3-/rm_cn_space";
|
|
4
4
|
|
|
@@ -43,8 +43,9 @@ const partition = async (li, title_number, remain_seg) => {
|
|
|
43
43
|
|
|
44
44
|
export default async (chat, txt) => {
|
|
45
45
|
if (!txt) {
|
|
46
|
-
return [];
|
|
46
|
+
return ["", []];
|
|
47
47
|
}
|
|
48
|
-
const li = txtLi(txt).map((i) => rmCnSpace(i))
|
|
49
|
-
|
|
48
|
+
const li = txtLi(txt).map((i) => rmCnSpace(i)),
|
|
49
|
+
[title, seg_li] = await segWithTitle(chat, li);
|
|
50
|
+
return [title, await partition(li, seg_li, repartition(chat, li.length))];
|
|
50
51
|
};
|
package/researchFmt.js
CHANGED
|
@@ -10,8 +10,8 @@ import SEARCH from './check/SEARCH.js';
|
|
|
10
10
|
import refmt from './refmt.js';
|
|
11
11
|
|
|
12
12
|
export default async(chat, txt) => {
|
|
13
|
-
var fmt, gen_txt, pli, search
|
|
14
|
-
pli = (await partition(chat, txt));
|
|
13
|
+
var fmt, gen_txt, pli, search, 文章标题;
|
|
14
|
+
[文章标题, pli] = (await partition(chat, txt));
|
|
15
15
|
if (!pli.length) {
|
|
16
16
|
return [];
|
|
17
17
|
}
|
|
@@ -45,5 +45,5 @@ export default async(chat, txt) => {
|
|
|
45
45
|
if (search.length) {
|
|
46
46
|
fmt += '# 机器投研\n\n' + search.map(refmt).join('\n');
|
|
47
47
|
}
|
|
48
|
-
return fmt;
|
|
48
|
+
return [文章标题, fmt];
|
|
49
49
|
};
|
package/seg.js
CHANGED
|
@@ -1,34 +1,64 @@
|
|
|
1
1
|
#!/usr/bin/env -S node --trace-uncaught --expose-gc --unhandled-rejections=strict --experimental-wasm-modules
|
|
2
|
+
var OPT, OPT_WITH_TITLE, gen;
|
|
3
|
+
|
|
2
4
|
import TYPE from './TYPE.js';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
OPT = {
|
|
7
|
+
type: TYPE.OBJECT,
|
|
8
|
+
required: ['li'],
|
|
9
|
+
properties: {
|
|
10
|
+
li: {
|
|
11
|
+
type: TYPE.ARRAY,
|
|
12
|
+
description: '拆分文章为多个章节,每个章节包含一系列问答对',
|
|
13
|
+
minItems: 1,
|
|
14
|
+
items: {
|
|
15
|
+
type: TYPE.OBJECT,
|
|
16
|
+
properties: {
|
|
17
|
+
题: {
|
|
18
|
+
description: '章节标题(只写标题,不写序号、注释)',
|
|
19
|
+
type: TYPE.STRING
|
|
20
|
+
},
|
|
21
|
+
行: {
|
|
22
|
+
description: '该章最后一句的行号',
|
|
23
|
+
type: TYPE.INTEGER
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
required: ['题', '行']
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
OPT_WITH_TITLE = structuredClone(OPT);
|
|
33
|
+
|
|
34
|
+
OPT_WITH_TITLE.required.push('题');
|
|
35
|
+
|
|
36
|
+
OPT_WITH_TITLE.properties.题 = {
|
|
37
|
+
type: TYPE.STRING,
|
|
38
|
+
description: '文章总标题(要简短)'
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
gen = async(opt, chat, txt_li) => {
|
|
42
|
+
var r, 提示词;
|
|
6
43
|
提示词 = `下文第1列为行号,第2列为对话内容,以tab分隔。
|
|
7
44
|
请划分章节,每章不要太长也不要太短,千字左右一章。
|
|
8
45
|
输出章节标题、每章最后一句号的行号。
|
|
9
46
|
输出格式为json数组:\n` + txt_li.map((i, pos) => {
|
|
10
47
|
return (pos + 1) + '\t' + i.trim();
|
|
11
48
|
}).join('\n');
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
description: '拆分文章为多个章节,每个章节包含一系列问答对',
|
|
15
|
-
minItems: 1,
|
|
16
|
-
items: {
|
|
17
|
-
type: TYPE.OBJECT,
|
|
18
|
-
properties: {
|
|
19
|
-
题: {
|
|
20
|
-
description: '章节标题(只写标题,不写注释)',
|
|
21
|
-
type: TYPE.STRING
|
|
22
|
-
},
|
|
23
|
-
行: {
|
|
24
|
-
description: '该章最后一句的行号',
|
|
25
|
-
type: TYPE.INTEGER
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
required: ['题', '行']
|
|
29
|
-
}
|
|
30
|
-
}, '你是专业资深的杂志编辑'));
|
|
31
|
-
return split_li.map((i) => {
|
|
49
|
+
r = (await chat(提示词, opt, '你是专业资深的杂志编辑'));
|
|
50
|
+
r.li = r.li.map((i) => {
|
|
32
51
|
return [i.题, i.行];
|
|
33
52
|
});
|
|
53
|
+
return r;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export default async(chat, txt_li) => {
|
|
57
|
+
return ((await gen(OPT, chat, txt_li))).li;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const segWithTitle = async(chat, txt_li) => {
|
|
61
|
+
var r;
|
|
62
|
+
r = (await gen(OPT_WITH_TITLE, chat, txt_li));
|
|
63
|
+
return [r.题, r.li];
|
|
34
64
|
};
|