@genai-fi/nanogpt 1.3.0 → 1.4.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/TeachableLLM.js +2 -0
- package/dist/api/responses.js +13 -10
- package/dist/api/training.d.ts +1 -0
- package/dist/api/training.js +2 -2
- package/dist/inference/Generator.js +3 -1
- package/dist/inference/tokenisePrompt.js +1 -1
- package/dist/inference/types.d.ts +2 -0
- package/package.json +1 -1
package/dist/TeachableLLM.js
CHANGED
|
@@ -201,6 +201,8 @@ var m = class m {
|
|
|
201
201
|
this._training?.training || this.setStatus("ready");
|
|
202
202
|
}), this._training.on("error", (e) => {
|
|
203
203
|
this.setStatus("error"), this.ee.emit("error", e);
|
|
204
|
+
}), this._training.on("mode", () => {
|
|
205
|
+
this.ee.emit("mode", this._model?.metaData.mode);
|
|
204
206
|
});
|
|
205
207
|
}
|
|
206
208
|
return this._training;
|
package/dist/api/responses.js
CHANGED
|
@@ -29,13 +29,10 @@ var r = class {
|
|
|
29
29
|
}
|
|
30
30
|
async _runForRecord(e, t, n) {
|
|
31
31
|
let r = t.previous_response_id ? this._responses.get(t.previous_response_id) : void 0;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
content: t.input
|
|
37
|
-
}] : t.input = e;
|
|
38
|
-
}
|
|
32
|
+
r && (t.input && Array.isArray(t.input) || t.input && typeof t.input == "string" && (t.input = [{
|
|
33
|
+
role: t.nonConversational ? "text" : "user",
|
|
34
|
+
content: t.input
|
|
35
|
+
}]));
|
|
39
36
|
let i = r ? r.generator : this._responses.get(e).generator, a = n ? () => n({
|
|
40
37
|
output: i.getConversation(),
|
|
41
38
|
id: e,
|
|
@@ -63,11 +60,17 @@ var r = class {
|
|
|
63
60
|
done: !1
|
|
64
61
|
};
|
|
65
62
|
return c.then((n) => {
|
|
66
|
-
o.done = !0, t.done = !0, t.output = n, this._hookedResponses.delete(e), this._resumeWaiters.delete(e)
|
|
63
|
+
o.done = !0, t.done = !0, t.output = n, this._hookedResponses.delete(e), this._resumeWaiters.delete(e);
|
|
64
|
+
let r = n[0]?._id || e;
|
|
65
|
+
n.forEach((e) => {
|
|
66
|
+
e._id === void 0 && (e._id = r);
|
|
67
|
+
}), a && i.off("tokens", a), this.ee.emit("done", e), this._processNextJob();
|
|
67
68
|
}), t;
|
|
68
69
|
}
|
|
69
|
-
let l = await c;
|
|
70
|
-
return
|
|
70
|
+
let l = await c, u = l[0]?._id || e;
|
|
71
|
+
return l.forEach((e) => {
|
|
72
|
+
e._id === void 0 && (e._id = u);
|
|
73
|
+
}), a && i.off("tokens", a), o.done = !0, this._hookedResponses.delete(e), this._resumeWaiters.delete(e), this.ee.emit("done", e), this._processNextJob(), {
|
|
71
74
|
output: l,
|
|
72
75
|
id: e,
|
|
73
76
|
done: !0
|
package/dist/api/training.d.ts
CHANGED
package/dist/api/training.js
CHANGED
|
@@ -152,8 +152,8 @@ var o = class {
|
|
|
152
152
|
u.datasetId = o.datasetId;
|
|
153
153
|
}
|
|
154
154
|
if (!u.trainDataset) try {
|
|
155
|
-
let t = await i(e, this._model, this._tokeniser, o, u.datasetId ?? a(s), c, s);
|
|
156
|
-
u.trainDataset =
|
|
155
|
+
let t = this._model.metaData.mode, n = await i(e, this._model, this._tokeniser, o, u.datasetId ?? a(s), c, s);
|
|
156
|
+
t !== this._model.metaData.mode && this.ee.emit("mode"), u.trainDataset = n.trainDataset, u.validationDataset = n.validationDataset, u.totalTokens = n.totalTokens;
|
|
157
157
|
} catch (e) {
|
|
158
158
|
throw this.setState(u, "error", /* @__PURE__ */ Error("prepare_data_failed")), u.trainer.dispose(), this._jobs.delete(u.id), e;
|
|
159
159
|
}
|
|
@@ -187,7 +187,9 @@ var y = class extends e {
|
|
|
187
187
|
this.reset();
|
|
188
188
|
}
|
|
189
189
|
initialise(e, n) {
|
|
190
|
-
if (this.cache && n?.noCache && this.reset(), this.initialPrompt = e || null, this.lastToken === -1 ? this.outputConversation =
|
|
190
|
+
if (this.cache && n?.noCache && this.reset(), this.initialPrompt = e || null, this.lastToken === -1 && this.outputConversation.length === 0 ? this.outputConversation = this.initialPrompt || [] : e && e.length > 0 && (e.forEach((e) => {
|
|
191
|
+
this.outputConversation.push(e);
|
|
192
|
+
}), this.resetCache()), !this.cache && !n?.noCache && (this.model.config.modelType !== "GenAI_NanoGPT_v1" || this.model.config.useRope)) {
|
|
191
193
|
let e = Array(this.model.config.nLayer);
|
|
192
194
|
for (let t = 0; t < this.model.config.nLayer; t++) e[t] = {
|
|
193
195
|
k: void 0,
|
|
@@ -3,7 +3,7 @@ import { I as e } from "../dist-Da20xy8E.js";
|
|
|
3
3
|
async function t(t, n, r, i) {
|
|
4
4
|
if (r) {
|
|
5
5
|
let a = r.length > 0 && (r[r.length - 1].role === "text" || r[r.length - 1].role === "assistant"), o;
|
|
6
|
-
return i?.nonConversational ? o = a && i?.continuation ? [t.bosToken, ...t.encode(r[r.length - 1].content)] : t.encodeAsSequence(r, !0) : a && i?.continuation ? (o = t.encodeConversation(r, !0), o[o.length - 1] === t.getSpecialTokenIndex("<|assistant_start|>") && o[o.length - 2] === t.getSpecialTokenIndex("<|assistant_end|>") && (o.pop(), o.pop())) : o = t.encodeConversation(r, !0), o.length > n && (o = o.slice(-n)), e([o], [1, o.length], "int32");
|
|
6
|
+
return i?.nonConversational ? o = a && i?.continuation ? [t.bosToken, ...t.encode(r[r.length - 1].content)] : t.encodeAsSequence(r, !0) : a && i?.continuation ? (o = t.encodeConversation(r, !0), o[o.length - 1] === t.getSpecialTokenIndex("<|assistant_start|>") && o[o.length - 2] === t.getSpecialTokenIndex("<|assistant_end|>") && (o.pop(), o.pop())) : o = t.encodeConversation(r, !0), o.length > n && (o = o.slice(-n)), i?.debug && console.log("Tokenised prompt:", t.decode(o)), e([o], [1, o.length], "int32");
|
|
7
7
|
} else {
|
|
8
8
|
let n = i?.nonConversational ? void 0 : t.getSpecialTokenIndex("<|assistant_start|>"), r = n === void 0 ? [t.bosToken] : [t.bosToken, n];
|
|
9
9
|
return e([r], [1, r.length], "int32");
|
|
@@ -17,6 +17,7 @@ export interface IGeneratorOutputInternal extends IGeneratorOutput {
|
|
|
17
17
|
outputTensor: Tensor;
|
|
18
18
|
}
|
|
19
19
|
export interface GeneratorConversation extends Conversation {
|
|
20
|
+
_id?: string;
|
|
20
21
|
_completed?: boolean;
|
|
21
22
|
_timestamp?: number;
|
|
22
23
|
_output?: IGeneratorOutput[];
|
|
@@ -45,6 +46,7 @@ export interface IGenerateOptions {
|
|
|
45
46
|
continuation?: boolean; /** Continue the previous response without adding a new turn. */
|
|
46
47
|
chunkSize?: number; /** Number of tokens to generate before returning a partial response. */
|
|
47
48
|
background?: boolean; /** Run the generation in the background and return immediately. */
|
|
49
|
+
debug?: boolean;
|
|
48
50
|
_onChunk?: (output: IGeneratorOutput) => void | Promise<void>;
|
|
49
51
|
}
|
|
50
52
|
export interface IGeneratorResponse {
|