@genai-fi/nanogpt 1.0.1 → 1.0.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.
@@ -103,7 +103,7 @@ var r = class {
103
103
  callback: t
104
104
  };
105
105
  if (this._responses.set(r, a), this._busyCount > 0 && !e.background) {
106
- if (this._jobQueue.length > 10) throw Error("Job queue is too long, rejecting new job");
106
+ if (this._jobQueue.length > 10) throw Error("queue_too_long");
107
107
  return new Promise((n, i) => {
108
108
  this._jobQueue.push({
109
109
  id: r,
@@ -121,7 +121,7 @@ var r = class {
121
121
  if (n) {
122
122
  let r = n.generator.getConversation();
123
123
  if (t !== void 0 && t >= 0 && t < r.length && r.splice(t), n.done = !1, n.timestamp = Date.now(), this._busyCount > 0 && !n.options.background) {
124
- if (this._jobQueue.length > 10) throw Error("Job queue is too long, rejecting new job");
124
+ if (this._jobQueue.length > 10) throw Error("queue_too_long");
125
125
  return new Promise((t, r) => {
126
126
  this._jobQueue.push({
127
127
  id: e,
@@ -134,7 +134,7 @@ var r = class {
134
134
  }
135
135
  return this._runForRecord(e, n.options, n.callback);
136
136
  }
137
- throw Error(`No response found for id: ${e}`);
137
+ throw Error("response_not_found");
138
138
  }
139
139
  getResponse(e) {
140
140
  let t = this._responses.get(e);
@@ -115,17 +115,17 @@ var o = class {
115
115
  this.setState(e, "error", t);
116
116
  }));
117
117
  }
118
- async job(e, a = [], o, s) {
119
- if (this.assertValidOptions(e), this.assertValidDataInput(a), this.assertValidDatasets(o), s && s instanceof t && s.tokeniserId !== this._tokeniser.id) throw Error("tokeniser_mismatch");
120
- let c = Array.from(this._jobs.keys());
121
- for (let t of c) {
118
+ async job(e, o = [], s, c) {
119
+ if (this.assertValidOptions(e), this.assertValidDataInput(o), this.assertValidDatasets(s), c && c instanceof t && c.tokeniserId !== this._tokeniser.id) throw Error("tokeniser_mismatch");
120
+ let l = Array.from(this._jobs.keys());
121
+ for (let t of l) {
122
122
  let n = this._jobs.get(t);
123
123
  if (n && n.id !== e.previous_job_id) {
124
124
  if (n.options.method.type === e.method.type && n.state !== "running") n.trainer.dispose(), this._jobs.delete(n.id);
125
125
  else if (n.options.method.type === e.method.type && n.state === "running") throw Error("training_in_progress");
126
126
  }
127
127
  }
128
- let l = e.previous_job_id ? this.getJob(e.previous_job_id) : {
128
+ let u = e.previous_job_id ? this.getJob(e.previous_job_id) : {
129
129
  id: n(),
130
130
  state: "pending",
131
131
  trainer: r(this._model, this._tokeniser, e),
@@ -134,40 +134,40 @@ var o = class {
134
134
  remaining: 0,
135
135
  options: e,
136
136
  totalTokens: 0,
137
- datasets: o,
137
+ datasets: s,
138
138
  breakOnLog: !1
139
139
  };
140
- if (!l) throw Error("invalid_previous_job_id");
141
- if (this._jobs.set(l.id, l), this.setState(l, "pending"), a instanceof t) {
142
- if (l.datasetId && a.datasetId !== l.datasetId) {
140
+ if (!u) throw Error("invalid_previous_job_id");
141
+ if (this._jobs.set(u.id, u), this.setState(u, "pending"), o instanceof t) {
142
+ if (u.datasetId && o.datasetId !== u.datasetId) {
143
143
  let e = /* @__PURE__ */ Error("dataset_mismatch");
144
- throw this.setState(l, "error", e), e;
144
+ throw this.setState(u, "error", e), e;
145
145
  }
146
- if (a.tokeniserId !== this._tokeniser.id) {
146
+ if (o.tokeniserId !== this._tokeniser.id) {
147
147
  let e = /* @__PURE__ */ Error("tokeniser_mismatch");
148
- throw this.setState(l, "error", e), e;
148
+ throw this.setState(u, "error", e), e;
149
149
  }
150
- l.datasetId = a.datasetId;
150
+ u.datasetId = o.datasetId;
151
151
  }
152
- if (!l.trainDataset) try {
153
- let t = await i(e, this._model, this._tokeniser, a, s, o);
154
- l.trainDataset = t.trainDataset, l.validationDataset = t.validationDataset, l.totalTokens = t.totalTokens;
152
+ if (!u.trainDataset) try {
153
+ let t = await i(e, this._model, this._tokeniser, o, u.datasetId ?? a(s), c, s);
154
+ u.trainDataset = t.trainDataset, u.validationDataset = t.validationDataset, u.totalTokens = t.totalTokens;
155
155
  } catch (e) {
156
- throw this.setState(l, "error", /* @__PURE__ */ Error("prepare_data_failed")), l.trainer.dispose(), this._jobs.delete(l.id), e;
156
+ throw this.setState(u, "error", /* @__PURE__ */ Error("prepare_data_failed")), u.trainer.dispose(), this._jobs.delete(u.id), e;
157
157
  }
158
158
  if (e.previous_job_id) {
159
- this.assertValidOptions(e), l.options = e;
159
+ this.assertValidOptions(e), u.options = e;
160
160
  try {
161
- l.trainer.configure(e);
161
+ u.trainer.configure(e);
162
162
  } catch (e) {
163
- throw this.setState(l, "error", /* @__PURE__ */ Error("trainer_configuration_failed")), l.trainer.dispose(), this._jobs.delete(l.id), e;
163
+ throw this.setState(u, "error", /* @__PURE__ */ Error("trainer_configuration_failed")), u.trainer.dispose(), this._jobs.delete(u.id), e;
164
164
  }
165
165
  } else try {
166
- l.trainer.configure(e);
166
+ u.trainer.configure(e);
167
167
  } catch (e) {
168
- throw this.setState(l, "error", /* @__PURE__ */ Error("trainer_configuration_failed")), l.trainer.dispose(), this._jobs.delete(l.id), e;
168
+ throw this.setState(u, "error", /* @__PURE__ */ Error("trainer_configuration_failed")), u.trainer.dispose(), this._jobs.delete(u.id), e;
169
169
  }
170
- return this.launchJob(l), l;
170
+ return this.launchJob(u), u;
171
171
  }
172
172
  getJob(e) {
173
173
  return this.assertValidJobId(e), this._jobs.get(e) ?? null;
@@ -195,7 +195,7 @@ var o = class {
195
195
  }
196
196
  dispose() {
197
197
  for (let e of this._jobs.values()) {
198
- if (e.state === "running") throw Error(`Cannot dispose training while job ${e.id} is still running`);
198
+ if (e.state === "running") throw Error("job_still_running");
199
199
  e.trainer.dispose();
200
200
  }
201
201
  this._jobs.clear(), this.ee.removeAllListeners();