@genai-fi/nanogpt 0.2.3 → 0.2.4

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.
@@ -1,6 +1,6 @@
1
1
  import { defaultConfig as d } from "./config.js";
2
- import u from "./NanoGPTModel.js";
3
- import { saveModel as m } from "./utilities/save.js";
2
+ import m from "./NanoGPTModel.js";
3
+ import { saveModel as u } from "./utilities/save.js";
4
4
  import { loadModel as l } from "./utilities/load.js";
5
5
  import f from "./Generator.js";
6
6
  import _ from "./Trainer.js";
@@ -8,6 +8,7 @@ import { E as c } from "./index-Dwqa6Zy2.js";
8
8
  import { dummyPassAsync as h } from "./utilities/dummy.js";
9
9
  import g from "./tokeniser/CharTokeniser.js";
10
10
  import "./papaparse.min-C8l2Kvo1.js";
11
+ import "./index-Tf7vU29b.js";
11
12
  class a extends c {
12
13
  _config;
13
14
  _model;
@@ -44,7 +45,7 @@ class a extends c {
44
45
  saveModel(t) {
45
46
  if (!this._model || !this._tokeniser)
46
47
  throw new Error("Model or tokeniser is not initialized.");
47
- return m(this._model, this._tokeniser, t);
48
+ return u(this._model, this._tokeniser, t);
48
49
  }
49
50
  static loadModel(t, r) {
50
51
  const e = new a(t);
@@ -59,7 +60,7 @@ class a extends c {
59
60
  }), e;
60
61
  }
61
62
  static create(t, r = {}) {
62
- const e = { ...d, ...r }, s = new g(e.vocabSize), o = new u(t, e), i = new a(t, s, o);
63
+ const e = { ...d, ...r }, s = new g(e.vocabSize), o = new m(t, e), i = new a(t, s, o);
63
64
  return i.setStatus("warmup"), h(o).then(() => {
64
65
  i.tokeniser.trained ? i.setStatus("ready") : (i.setStatus("awaitingTokens"), i.tokeniser.once("trainStatus", (n) => {
65
66
  n === "trained" && i.setStatus("ready");
@@ -1,12 +1,14 @@
1
- async function p(s, f = 104857600, e = "text") {
2
- const r = await (await import("../parquet-DpcqBLb0.js").then((t) => t.p)).ParquetReader.openBuffer(Buffer.from(await s.arrayBuffer())), a = [], i = r.getCursor([[e]]);
1
+ import { B as n } from "../index-Tf7vU29b.js";
2
+ const p = 100 * 1024 * 1024;
3
+ async function w(s, f = p, r = "text") {
4
+ const e = await (await import("../parquet-BRl5lE_I.js").then((t) => t.p)).ParquetReader.openBuffer(n.from(await s.arrayBuffer())), a = [], i = e.getCursor([[r]]);
3
5
  let o = 0;
4
6
  for (; ; ) {
5
7
  const t = await i.next();
6
- if (!t || !t[e] || typeof t[e] != "string" || (a.push(t[e]), o += t[e].length, o > f)) break;
8
+ if (!t || !t[r] || typeof t[r] != "string" || (a.push(t[r]), o += t[r].length, o > f)) break;
7
9
  }
8
- return r.close(), a;
10
+ return e.close(), a;
9
11
  }
10
12
  export {
11
- p as loadParquet
13
+ w as loadParquet
12
14
  };
@@ -0,0 +1 @@
1
+ export declare function loadPDF(file: File, maxSize?: number): Promise<string[]>;
@@ -0,0 +1,12 @@
1
+ async function u(s, i = 104857600) {
2
+ const e = await (await import("../pdf-kJD-f258.js")).getDocument({ data: await s.arrayBuffer() }).promise, c = e.numPages, a = [];
3
+ let n = 0;
4
+ for (let t = 1; t <= c; t++) {
5
+ const o = (await (await e.getPage(t)).getTextContent()).items.map((g) => g.str).join(" ");
6
+ if (a.push(o), n += o.length, n > i) break;
7
+ }
8
+ return a;
9
+ }
10
+ export {
11
+ u as loadPDF
12
+ };
@@ -1,54 +1,59 @@
1
- import { p as u } from "../papaparse.min-C8l2Kvo1.js";
1
+ import { p as s } from "../papaparse.min-C8l2Kvo1.js";
2
2
  import { loadParquet as d } from "./parquet.js";
3
+ import { loadPDF as m } from "./pdf.js";
3
4
  function x(e, t) {
4
- const r = e.findIndex((n) => n.toLowerCase() === t.toLowerCase());
5
- return r === -1 ? 0 : r;
5
+ const a = e.findIndex((n) => n.toLowerCase() === t.toLowerCase());
6
+ return a === -1 ? 0 : a;
6
7
  }
7
- function l(e) {
8
+ function f(e) {
8
9
  return e.every((t) => t.length < 64);
9
10
  }
10
- function m(e) {
11
+ function l(e) {
11
12
  return e.split(".").pop() || "";
12
13
  }
13
- function f(e) {
14
- switch (m(e)) {
14
+ function w(e) {
15
+ switch (l(e)) {
15
16
  case "parquet":
16
17
  return "application/parquet";
17
18
  case "csv":
18
19
  return "text/csv";
19
20
  case "txt":
20
21
  return "text/plain";
22
+ case "pdf":
23
+ return "application/pdf";
21
24
  default:
22
25
  return "unknown";
23
26
  }
24
27
  }
25
- async function g(e, t) {
26
- const r = e.type !== "" ? e.type : f(e.name);
27
- if (r === "application/parquet")
28
+ async function q(e, t) {
29
+ const a = e.type !== "" ? e.type : w(e.name);
30
+ if (a === "application/parquet")
28
31
  return d(e, t?.maxSize, t?.column);
29
- if (r === "text/csv") {
32
+ if (a === "application/pdf")
33
+ return m(e, t?.maxSize);
34
+ if (a === "text/csv") {
30
35
  const n = await e.text();
31
- return new Promise((c, o) => {
32
- u.parse(n, {
36
+ return new Promise((p, o) => {
37
+ s.parse(n, {
33
38
  header: !1,
34
39
  skipEmptyLines: !0,
35
- complete: (a) => {
36
- if (a.errors.length > 0)
40
+ complete: (r) => {
41
+ if (r.errors.length > 0)
37
42
  o(new Error("Error parsing file"));
38
43
  else {
39
- const p = x(a.data[0], t?.column || "text"), i = t?.hasHeader ?? l(a.data[0]) ? a.data.slice(1) : a.data;
40
- c(i.map((s) => s[p]));
44
+ const c = x(r.data[0], t?.column || "text"), i = t?.hasHeader ?? f(r.data[0]) ? r.data.slice(1) : r.data;
45
+ p(i.map((u) => u[c]));
41
46
  }
42
47
  },
43
- error: (a) => {
44
- o(a);
48
+ error: (r) => {
49
+ o(r);
45
50
  }
46
51
  });
47
52
  });
48
- } else if (r === "text/plain")
53
+ } else if (a === "text/plain")
49
54
  return [await e.text()];
50
- throw new Error(`Unsupported file type: ${r}`);
55
+ throw new Error(`Unsupported file type: ${a}`);
51
56
  }
52
57
  export {
53
- g as default
58
+ q as default
54
59
  };
@@ -0,0 +1,4 @@
1
+ const l = globalThis || void 0 || self;
2
+ export {
3
+ l as g
4
+ };