@genai-fi/nanogpt 1.0.2 → 1.0.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.
@@ -523,7 +523,7 @@ function d(e) {
523
523
  }
524
524
  async function f(e, t) {
525
525
  let u = e.type === "" ? e instanceof File ? d(e.name) : "application/zip" : e.type;
526
- if (u === "application/parquet") throw Error("Parquet loading is not currently supported in the browser. Please convert your data to JSONL format.");
526
+ if (u === "application/parquet") throw Error("unsupported_file_type");
527
527
  if (u === "application/pdf") return new i(await n(e, t?.maxSize));
528
528
  if (u === "application/vnd.openxmlformats-officedocument.wordprocessingml.document") return new i(await r(e));
529
529
  if (u === "application/json") {
@@ -538,7 +538,7 @@ async function f(e, t) {
538
538
  role: "text",
539
539
  content: JSON.stringify(e)
540
540
  }]));
541
- throw Error("Expected JSON array");
541
+ throw Error("bad_format");
542
542
  }
543
543
  if (u === "application/jsonl") return new o(e);
544
544
  if (u === "application/zip") return new a(e);
@@ -550,7 +550,7 @@ async function f(e, t) {
550
550
  skipEmptyLines: !0,
551
551
  delimiter: ",",
552
552
  complete: (n) => {
553
- if (n.errors.length > 0) console.error(n.errors), r(/* @__PURE__ */ Error("Error parsing file"));
553
+ if (n.errors.length > 0) console.error(n.errors), r(/* @__PURE__ */ Error("bad_format"));
554
554
  else {
555
555
  let r = c(n.data[0], t?.column || "text");
556
556
  e(new i((t?.hasHeader ?? l(n.data[0]) ? n.data.slice(1) : n.data).map((e) => [{
@@ -568,7 +568,7 @@ async function f(e, t) {
568
568
  role: "text",
569
569
  content: await e.text()
570
570
  }]]);
571
- throw Error(`Unsupported file type: ${u}`);
571
+ throw Error("unsupported_file_type");
572
572
  }
573
573
  //#endregion
574
574
  export { f as default };
@@ -34,6 +34,7 @@ export default class Generator extends EE<'start' | 'stop' | 'tokens' | 'reset'>
34
34
  private startTime;
35
35
  private tokenCount;
36
36
  constructor(model: Model<ModelForwardAttributes>, tokeniser: ITokeniser);
37
+ private shouldTerminate;
37
38
  /** Generate logits and select a token. */
38
39
  private _generateToken;
39
40
  /** Generate multiple tokens in a loop and produce text */
@@ -40,6 +40,11 @@ var b = class extends e {
40
40
  constructor(e, t) {
41
41
  super(), this.model = e, this.tokeniser = t, this.actualTokeniser = t;
42
42
  }
43
+ shouldTerminate(e, t) {
44
+ if (e) return !1;
45
+ let n = this.tokeniser.getSpecialTokenIndex("<|assistant_end|>");
46
+ return t === this.actualTokeniser.eosToken || t === n;
47
+ }
43
48
  async _generateToken(e, t, n) {
44
49
  let s = n?.temperature ?? 1, h = n?.topK, _ = n?.topP, v = n?.usePadding ?? !1, y = {
45
50
  training: !1,
@@ -132,7 +137,7 @@ var b = class extends e {
132
137
  S.dispose(), S = E;
133
138
  let D = (await S.array())[0][0], O = this.actualTokeniser.decode([D]);
134
139
  this.lastToken = D;
135
- let k = !n?.allowSpecial && this.tokeniser.isSpecialToken(D), A = {
140
+ let k = this.shouldTerminate(n?.allowSpecial ?? !1, D), A = {
136
141
  outputTensor: S,
137
142
  token: D,
138
143
  text: O,
@@ -7,7 +7,7 @@ async function e(e) {
7
7
  if (t) try {
8
8
  n = JSON.parse(t);
9
9
  } catch (e) {
10
- throw console.error(e), Error("Failed to parse meta.json in the zip archive", { cause: e });
10
+ throw console.error(e), Error("bad_format", { cause: e });
11
11
  }
12
12
  else console.warn("meta.json not found in the zip archive, using default metadata");
13
13
  return n;
@@ -36,6 +36,7 @@ export interface DatasetMetadata {
36
36
  id: string;
37
37
  name: string;
38
38
  conversational: boolean;
39
+ url?: string;
39
40
  }
40
41
  export interface ActionLogEntry {
41
42
  action: 'pretrain' | 'generate' | 'finetune';
@@ -31,7 +31,7 @@ function n(e) {
31
31
  if (e.windowSize !== void 0 && typeof e.windowSize != "string") throw Error("Invalid config: \"windowSize\" must be a string for GenAI_NanoGPT_v2.");
32
32
  return;
33
33
  }
34
- throw Error("Invalid config: \"modelType\" must be \"GenAI_NanoGPT_v1\" or \"GenAI_NanoGPT_v2\".");
34
+ throw Error("invalid_model_type");
35
35
  }
36
36
  //#endregion
37
37
  export { e as defaultConfig, n as validateConfig };