@3-/aiapi 0.1.47 → 0.1.49
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/fmtJson.js +2 -4
- package/package.json +1 -1
- package/partition.js +19 -9
package/fmtJson.js
CHANGED
|
@@ -3,15 +3,13 @@ import fmtSeg from './fmtSeg.js';
|
|
|
3
3
|
|
|
4
4
|
import partition from './partition.js';
|
|
5
5
|
|
|
6
|
-
import seg from './seg.js';
|
|
7
|
-
|
|
8
6
|
export default async(chat, txt) => {
|
|
9
7
|
var gen, i, pli, result, sum, tmp, txt_li;
|
|
10
8
|
if (!txt) {
|
|
11
9
|
return [];
|
|
12
10
|
}
|
|
13
|
-
txt_li = txt.split('\n');
|
|
14
|
-
pli = (await partition(chat, txt_li
|
|
11
|
+
txt_li = txt.replaceAll('\r\n', '\n').replaceAll('\r', '\n').split('\n');
|
|
12
|
+
pli = (await partition(chat, txt_li));
|
|
15
13
|
result = [];
|
|
16
14
|
sum = 0;
|
|
17
15
|
tmp = [];
|
package/package.json
CHANGED
package/partition.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import seg from "./seg.js"
|
|
2
2
|
|
|
3
|
-
const partition = async (
|
|
3
|
+
const partition = async (li, title_number, remain_seg) => {
|
|
4
4
|
let title = ""
|
|
5
5
|
const order = title_number.sort((a, b) => a[1] - b[1])
|
|
6
6
|
const result = []
|
|
@@ -9,16 +9,16 @@ const partition = async (lines, title_number, remain_seg) => {
|
|
|
9
9
|
for (const [t, row] of order) {
|
|
10
10
|
console.log(t)
|
|
11
11
|
const index = row - 1
|
|
12
|
-
result.push(title +
|
|
12
|
+
result.push(title + li.slice(start, index).join("\n"))
|
|
13
13
|
title = "# " + t + "\n"
|
|
14
14
|
start = index
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
if (start <
|
|
18
|
-
|
|
19
|
-
const remain =
|
|
17
|
+
if (start < li.length) {
|
|
18
|
+
li = li.slice(start)
|
|
19
|
+
const remain = li.join("\n")
|
|
20
20
|
if (remain.length > 6000) {
|
|
21
|
-
return result.concat(await remain_seg(
|
|
21
|
+
return result.concat(await remain_seg(li))
|
|
22
22
|
} else {
|
|
23
23
|
result.push(title + remain)
|
|
24
24
|
}
|
|
@@ -27,7 +27,17 @@ const partition = async (lines, title_number, remain_seg) => {
|
|
|
27
27
|
return result
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const repartition = (chat, len) => async (li) => {
|
|
31
|
+
if (li.length == len) {
|
|
32
|
+
return li
|
|
33
|
+
}
|
|
34
|
+
if (li.length == 1) {
|
|
35
|
+
li = li[0].split("。")
|
|
36
|
+
}
|
|
37
|
+
return partition(li, await seg(chat, li), (i) =>
|
|
38
|
+
repartition(chat, li.length)(i),
|
|
33
39
|
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default async (chat, li) =>
|
|
43
|
+
partition(li, await seg(chat, li), repartition(chat, li.length))
|