@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.
@@ -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[][]>;
@@ -1,20 +1,20 @@
1
- import { p as u } from "../papaparse.min-C0cScC2i.js";
2
- import { loadParquet as f } from "./parquet.js";
3
- import { loadPDF as d } from "./pdf.js";
4
- import { loadDOCX as x } from "./docx.js";
5
- import { z as m } from "../jszip.min-BZhlzntC.js";
6
- function y(t, r) {
7
- const n = t.findIndex((i) => i.toLowerCase() === r.toLowerCase());
8
- return n === -1 ? 0 : n;
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 w(t) {
11
- return t.every((r) => r.length < 64);
10
+ function z(t) {
11
+ return t.every((e) => e.length < 64);
12
12
  }
13
- function h(t) {
13
+ function j(t) {
14
14
  return t.split(".").pop() || "";
15
15
  }
16
- function g(t) {
17
- switch (h(t)) {
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 z(t) {
38
+ function E(t) {
39
39
  if (!Array.isArray(t)) return !1;
40
- const r = t[0];
41
- return typeof r == "object" && r !== null && "role" in r && "content" in r && typeof r.role == "string" && typeof r.content == "string";
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 j(t, r) {
44
- const n = t.type !== "" ? t.type : g(t.name);
45
- if (n === "application/parquet")
46
- return f(t, r?.maxSize, r?.column);
47
- if (n === "application/pdf")
48
- return d(t, r?.maxSize);
49
- if (n === "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
50
- return x(t);
51
- if (n === "application/json") {
52
- const i = await t.text(), o = JSON.parse(i);
53
- if (Array.isArray(o))
54
- return o.map((e) => [
55
- typeof e == "string" ? { role: "text", content: e } : "text" in e ? { role: "text", content: e.text } : { role: "text", content: JSON.stringify(e) }
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 (n === "application/jsonl")
60
- return (await t.text()).split(`
61
- `).filter((o) => o.trim() !== "").map((o) => {
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 e = JSON.parse(o);
64
- return z(e) ? e : [
65
- typeof e == "string" ? { role: "text", content: e } : "text" in e ? { role: "text", content: e.text } : { role: "text", content: JSON.stringify(e) }
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: o }];
70
+ return [{ role: "text", content: a }];
69
71
  }
70
72
  });
71
- if (n === "application/zip") {
72
- const i = await m.loadAsync(t), o = [];
73
- for (const e of Object.keys(i.files)) {
74
- const a = i.file(e);
75
- if (a) {
76
- const c = await a.async("blob"), s = await j(new File([c], e), r);
77
- o.push(...s);
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 o;
90
+ return a;
81
91
  }
82
- if (n === "text/csv") {
83
- const i = await t.text();
84
- return new Promise((o, e) => {
85
- u.parse(i, {
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: (a) => {
90
- if (a.errors.length > 0)
91
- console.error(a.errors), e(new Error("Error parsing file"));
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 c = y(a.data[0], r?.column || "text"), p = r?.hasHeader ?? w(a.data[0]) ? a.data.slice(1) : a.data;
94
- o(p.map((l) => [{ role: "text", content: l[c] }]));
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: (a) => {
98
- e(a);
107
+ error: (n) => {
108
+ r(n);
99
109
  }
100
110
  });
101
111
  });
102
- } else if (n === "text/plain")
112
+ } else if (s === "text/plain")
103
113
  return [[{ role: "text", content: await t.text() }]];
104
- throw new Error(`Unsupported file type: ${n}`);
114
+ throw new Error(`Unsupported file type: ${s}`);
105
115
  }
106
116
  export {
107
- j as default
117
+ O as default
108
118
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genai-fi/nanogpt",
3
- "version": "0.19.0",
3
+ "version": "0.19.1",
4
4
  "type": "module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",