@genai-fi/nanogpt 1.2.2 → 1.2.3

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.
@@ -79,8 +79,9 @@ var f = class {
79
79
  text: "",
80
80
  terminated: !1,
81
81
  context: a.context,
82
- contextLength: a.contextLength
83
- }], s = t.maxBeamLength, c = t.endOnWhiteSpace === !0 ? Math.max(s, t.maxLength ?? s + this.model.config.blockSize) : s, l = Date.now();
82
+ contextLength: a.contextLength,
83
+ candidates: 0
84
+ }], s = t.maxBeamLength, c = t.endOnWhiteSpace === !0 ? Math.max(s, t.maxLength ?? s + this.model.config.blockSize) : s, l = Date.now(), u = 0;
84
85
  for (let e = 0; e < c && this.active; e++) {
85
86
  let e = o.filter((e) => !e.terminated);
86
87
  if (e.length === 0) break;
@@ -107,26 +108,42 @@ var f = class {
107
108
  let t = e.terminatedByToken || e.terminatedByWhitespace, n = !e.dropLeadingWhitespaceTerminator, i = n ? e.parent.tokens.concat(e.token) : e.parent.tokens.slice(), a = e.terminatedByToken || e.dropLeadingWhitespaceTerminator ? e.parent.text : e.parent.text + e.tokenText, o = n ? this.appendTokenToContext(e.parent.context, e.parent.contextLength, e.token) : {
108
109
  context: e.parent.context.clone(),
109
110
  contextLength: e.parent.contextLength
110
- };
111
- c.push({
111
+ }, s = e.parent._output?.slice() ?? [];
112
+ n && s.push({
113
+ token: e.token,
114
+ score: e.score,
115
+ text: e.tokenText,
116
+ terminated: t,
117
+ confidence: null,
118
+ logits: null,
119
+ scores: null,
120
+ hiddenStates: null,
121
+ attention: null,
122
+ loss: null,
123
+ multinomialRand: null
124
+ }), c.push({
112
125
  tokens: i,
113
126
  score: e.score,
114
127
  text: a,
115
128
  terminated: t,
116
129
  context: o.context,
117
- contextLength: o.contextLength
130
+ contextLength: o.contextLength,
131
+ _output: s,
132
+ candidates: u
118
133
  });
119
134
  }
120
- if (o.forEach((e) => e.context.dispose()), c.length === 0) break;
135
+ if (u += a.length - c.length, o.forEach((e) => e.context.dispose()), c.length === 0) break;
121
136
  o = c, n && Date.now() - l >= 40 && (n(o.slice(0, t.beams)), l = Date.now());
122
137
  }
123
- this.active = !1;
124
- let u = o.slice().sort((e, t) => t.score - e.score), f = [], p = /* @__PURE__ */ new Set();
125
- for (let e of u) {
138
+ this.active = !1, u += o.length;
139
+ let f = o.slice().sort((e, t) => t.score - e.score), p = [], m = /* @__PURE__ */ new Set();
140
+ for (let e of f) {
126
141
  let n = e.text.trim();
127
- if (p.has(n) || (p.add(n), f.push(e)), f.length >= t.beams) break;
142
+ if (m.has(n) || (m.add(n), p.push(e)), p.length >= t.beams) break;
128
143
  }
129
- return o.forEach((e) => e.context.dispose()), f;
144
+ return o.forEach((e) => {
145
+ e.context.dispose(), e.candidates = u;
146
+ }), p;
130
147
  }
131
148
  };
132
149
  //#endregion
@@ -1,7 +1,6 @@
1
1
  import { Conversation } from '../tokeniser/type';
2
2
  import { Tensor } from '@tensorflow/tfjs-core';
3
3
  export interface IGeneratorOutput {
4
- outputTensor: Tensor;
5
4
  token: number;
6
5
  text: string;
7
6
  confidence: number | null;
@@ -14,6 +13,9 @@ export interface IGeneratorOutput {
14
13
  multinomialRand: number | null;
15
14
  terminated: boolean;
16
15
  }
16
+ export interface IGeneratorOutputInternal extends IGeneratorOutput {
17
+ outputTensor: Tensor;
18
+ }
17
19
  export interface GeneratorConversation extends Conversation {
18
20
  _completed?: boolean;
19
21
  _timestamp?: number;
@@ -59,4 +61,6 @@ export interface IBeam {
59
61
  tokens: number[];
60
62
  score: number;
61
63
  text: string;
64
+ candidates: number;
65
+ _output?: IGeneratorOutput[];
62
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genai-fi/nanogpt",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "type": "module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",