@genai-fi/nanogpt 0.19.0 → 0.19.1
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/dist/data/textLoader.d.ts +1 -1
- package/dist/data/textLoader.js +68 -58
- package/package.json +1 -1
|
@@ -4,4 +4,4 @@ export interface DataOptions {
|
|
|
4
4
|
column?: string;
|
|
5
5
|
hasHeader?: boolean;
|
|
6
6
|
}
|
|
7
|
-
export default function loadTextData(file: File, options?: DataOptions): Promise<Conversation[][]>;
|
|
7
|
+
export default function loadTextData(file: File, options?: DataOptions, cb?: (progress: number) => void): Promise<Conversation[][]>;
|
package/dist/data/textLoader.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { p as
|
|
2
|
-
import { loadParquet as
|
|
3
|
-
import { loadPDF as
|
|
4
|
-
import { loadDOCX as
|
|
5
|
-
import { z as
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
return
|
|
1
|
+
import { p as x } from "../papaparse.min-C0cScC2i.js";
|
|
2
|
+
import { loadParquet as m } from "./parquet.js";
|
|
3
|
+
import { loadPDF as y } from "./pdf.js";
|
|
4
|
+
import { loadDOCX as g } from "./docx.js";
|
|
5
|
+
import { z as w } from "../jszip.min-BZhlzntC.js";
|
|
6
|
+
function h(t, e) {
|
|
7
|
+
const o = t.findIndex((s) => s.toLowerCase() === e.toLowerCase());
|
|
8
|
+
return o === -1 ? 0 : o;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
return t.every((
|
|
10
|
+
function z(t) {
|
|
11
|
+
return t.every((e) => e.length < 64);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function j(t) {
|
|
14
14
|
return t.split(".").pop() || "";
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
switch (
|
|
16
|
+
function v(t) {
|
|
17
|
+
switch (j(t)) {
|
|
18
18
|
case "json":
|
|
19
19
|
return "application/json";
|
|
20
20
|
case "jsonl":
|
|
@@ -35,74 +35,84 @@ function g(t) {
|
|
|
35
35
|
return "unknown";
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function E(t) {
|
|
39
39
|
if (!Array.isArray(t)) return !1;
|
|
40
|
-
const
|
|
41
|
-
return typeof
|
|
40
|
+
const e = t[0];
|
|
41
|
+
return typeof e == "object" && e !== null && "role" in e && "content" in e && typeof e.role == "string" && typeof e.content == "string";
|
|
42
42
|
}
|
|
43
|
-
async function
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
return
|
|
47
|
-
if (
|
|
48
|
-
return
|
|
49
|
-
if (
|
|
50
|
-
return
|
|
51
|
-
if (
|
|
52
|
-
const
|
|
53
|
-
if (Array.isArray(
|
|
54
|
-
return
|
|
55
|
-
typeof
|
|
43
|
+
async function O(t, e, o) {
|
|
44
|
+
const s = t.type !== "" ? t.type : v(t.name);
|
|
45
|
+
if (s === "application/parquet")
|
|
46
|
+
return m(t, e?.maxSize, e?.column);
|
|
47
|
+
if (s === "application/pdf")
|
|
48
|
+
return y(t, e?.maxSize);
|
|
49
|
+
if (s === "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|
|
50
|
+
return g(t);
|
|
51
|
+
if (s === "application/json") {
|
|
52
|
+
const c = await t.text(), a = JSON.parse(c);
|
|
53
|
+
if (Array.isArray(a))
|
|
54
|
+
return a.map((r) => [
|
|
55
|
+
typeof r == "string" ? { role: "text", content: r } : "text" in r ? { role: "text", content: r.text } : { role: "text", content: JSON.stringify(r) }
|
|
56
56
|
]);
|
|
57
57
|
throw new Error("Expected JSON array");
|
|
58
58
|
}
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
if (s === "application/jsonl") {
|
|
60
|
+
const c = await t.text();
|
|
61
|
+
return o && o(0.1), c.split(`
|
|
62
|
+
`).filter((a) => a.trim() !== "").map((a, r, n) => {
|
|
63
|
+
o && r % 1e3 === 0 && o(0.1 + r / n.length * 0.9);
|
|
62
64
|
try {
|
|
63
|
-
const
|
|
64
|
-
return
|
|
65
|
-
typeof
|
|
65
|
+
const i = JSON.parse(a);
|
|
66
|
+
return E(i) ? i : [
|
|
67
|
+
typeof i == "string" ? { role: "text", content: i } : "text" in i ? { role: "text", content: i.text } : { role: "text", content: JSON.stringify(i) }
|
|
66
68
|
];
|
|
67
69
|
} catch {
|
|
68
|
-
return [{ role: "text", content:
|
|
70
|
+
return [{ role: "text", content: a }];
|
|
69
71
|
}
|
|
70
72
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
}
|
|
74
|
+
if (s === "application/zip") {
|
|
75
|
+
const c = await w.loadAsync(t);
|
|
76
|
+
let a = [];
|
|
77
|
+
const r = Object.keys(c.files);
|
|
78
|
+
for (let n = 0; n < r.length; n++) {
|
|
79
|
+
const i = r[n], p = c.file(i);
|
|
80
|
+
if (p) {
|
|
81
|
+
const l = await p.async("blob", (u) => {
|
|
82
|
+
if (o) {
|
|
83
|
+
const d = 0.1 + (u.percent / 100 * 0.9 / r.length + n / r.length * 0.9);
|
|
84
|
+
o(d);
|
|
85
|
+
}
|
|
86
|
+
}), f = await O(new File([l], i), e);
|
|
87
|
+
o && o(0.1 + (n + 1) / r.length * 0.9), a = a.concat(f);
|
|
78
88
|
}
|
|
79
89
|
}
|
|
80
|
-
return
|
|
90
|
+
return a;
|
|
81
91
|
}
|
|
82
|
-
if (
|
|
83
|
-
const
|
|
84
|
-
return new Promise((
|
|
85
|
-
|
|
92
|
+
if (s === "text/csv") {
|
|
93
|
+
const c = await t.text();
|
|
94
|
+
return o && o(0.1), new Promise((a, r) => {
|
|
95
|
+
x.parse(c, {
|
|
86
96
|
header: !1,
|
|
87
97
|
skipEmptyLines: !0,
|
|
88
98
|
delimiter: ",",
|
|
89
|
-
complete: (
|
|
90
|
-
if (
|
|
91
|
-
console.error(
|
|
99
|
+
complete: (n) => {
|
|
100
|
+
if (n.errors.length > 0)
|
|
101
|
+
console.error(n.errors), r(new Error("Error parsing file"));
|
|
92
102
|
else {
|
|
93
|
-
const
|
|
94
|
-
|
|
103
|
+
const i = h(n.data[0], e?.column || "text"), l = e?.hasHeader ?? z(n.data[0]) ? n.data.slice(1) : n.data;
|
|
104
|
+
a(l.map((f) => [{ role: "text", content: f[i] }]));
|
|
95
105
|
}
|
|
96
106
|
},
|
|
97
|
-
error: (
|
|
98
|
-
|
|
107
|
+
error: (n) => {
|
|
108
|
+
r(n);
|
|
99
109
|
}
|
|
100
110
|
});
|
|
101
111
|
});
|
|
102
|
-
} else if (
|
|
112
|
+
} else if (s === "text/plain")
|
|
103
113
|
return [[{ role: "text", content: await t.text() }]];
|
|
104
|
-
throw new Error(`Unsupported file type: ${
|
|
114
|
+
throw new Error(`Unsupported file type: ${s}`);
|
|
105
115
|
}
|
|
106
116
|
export {
|
|
107
|
-
|
|
117
|
+
O as default
|
|
108
118
|
};
|