@3-/aiapi 0.1.47 → 0.1.48

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/partition.js +20 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3-/aiapi",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://atomgit.com/i18n/lib.git"
package/partition.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import seg from "./seg.js"
2
2
 
3
- const partition = async (lines, title_number, remain_seg) => {
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 + lines.slice(start, index).join("\n"))
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 < lines.length) {
18
- lines = lines.slice(start)
19
- const remain = lines.join("\n")
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(lines))
21
+ return result.concat(await remain_seg(li))
22
22
  } else {
23
23
  result.push(title + remain)
24
24
  }
@@ -27,7 +27,18 @@ const partition = async (lines, title_number, remain_seg) => {
27
27
  return result
28
28
  }
29
29
 
30
- export default (chat, lines, title_number) =>
31
- partition(lines, title_number, async (li) =>
32
- partition(li, await seg(chat, li), (i) => i),
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 (chat, li, title_number) => {
43
+ return partition(li, title_number, repartition(chat, li.length))
44
+ }