@ariacompute/engine-ts 1.6.1 → 1.6.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.
- package/dist/index.d.ts +6 -0
- package/dist/index.js +18 -16
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,12 @@ export declare function isLocalRef(modelRef: string): boolean;
|
|
|
47
47
|
export declare class Engine {
|
|
48
48
|
private lib;
|
|
49
49
|
private handle;
|
|
50
|
+
private fnInit;
|
|
51
|
+
private fnDestroy;
|
|
52
|
+
private fnComplete;
|
|
53
|
+
private fnEmbed;
|
|
54
|
+
private fnTranscribe;
|
|
55
|
+
private fnLastError;
|
|
50
56
|
/** Construct from a local bundle directory. */
|
|
51
57
|
constructor(bundle: string, opts?: OpenOptions);
|
|
52
58
|
/** Auto-detect: a value containing a separator or already on disk is a local
|
package/dist/index.js
CHANGED
|
@@ -173,15 +173,15 @@ class Engine {
|
|
|
173
173
|
/** Construct from a local bundle directory. */
|
|
174
174
|
constructor(bundle, opts = {}) {
|
|
175
175
|
this.lib = loadLib(opts.ffiLib);
|
|
176
|
-
this.lib.func("aria_model_init", "void*", ["str"]);
|
|
177
|
-
this.lib.func("aria_model_destroy", "void", ["void*"]);
|
|
178
|
-
this.lib.func("aria_complete", "int", ["void*", "str", "str", "str", "
|
|
179
|
-
this.lib.func("aria_embed", "int", ["void*", "str", "
|
|
180
|
-
this.lib.func("aria_transcribe", "int", ["void*", "void*", "size_t", "str", "
|
|
181
|
-
this.lib.func("aria_last_error", "str", []);
|
|
182
|
-
this.handle = this.
|
|
176
|
+
this.fnInit = this.lib.func("aria_model_init", "void*", ["str"]);
|
|
177
|
+
this.fnDestroy = this.lib.func("aria_model_destroy", "void", ["void*"]);
|
|
178
|
+
this.fnComplete = this.lib.func("aria_complete", "int", ["void*", "str", "str", "str", "void*", "size_t"]);
|
|
179
|
+
this.fnEmbed = this.lib.func("aria_embed", "int", ["void*", "str", "void*", "size_t"]);
|
|
180
|
+
this.fnTranscribe = this.lib.func("aria_transcribe", "int", ["void*", "void*", "size_t", "str", "void*", "size_t"]);
|
|
181
|
+
this.fnLastError = this.lib.func("aria_last_error", "str", []);
|
|
182
|
+
this.handle = this.fnInit(bundle);
|
|
183
183
|
if (!this.handle) {
|
|
184
|
-
const err = this.
|
|
184
|
+
const err = this.fnLastError();
|
|
185
185
|
throw new Error(err || "init failed");
|
|
186
186
|
}
|
|
187
187
|
}
|
|
@@ -198,11 +198,13 @@ class Engine {
|
|
|
198
198
|
return new Engine(bundle, opts);
|
|
199
199
|
}
|
|
200
200
|
complete(messages, opts = {}) {
|
|
201
|
-
const
|
|
201
|
+
const messagesJson = JSON.stringify(messages);
|
|
202
|
+
const optionsJson = JSON.stringify(opts || { max_tokens: 16 });
|
|
203
|
+
const toolsJson = JSON.stringify([]);
|
|
202
204
|
const buf = Buffer.alloc(1 << 16);
|
|
203
|
-
const rc = this.
|
|
205
|
+
const rc = this.fnComplete(this.handle, messagesJson, optionsJson, toolsJson, buf, buf.length);
|
|
204
206
|
if (rc !== 0) {
|
|
205
|
-
const err = this.
|
|
207
|
+
const err = this.fnLastError();
|
|
206
208
|
return { success: false, response: "", error: err || "complete failed" };
|
|
207
209
|
}
|
|
208
210
|
try {
|
|
@@ -215,25 +217,25 @@ class Engine {
|
|
|
215
217
|
}
|
|
216
218
|
embed(text) {
|
|
217
219
|
const buf = Buffer.alloc(1 << 20);
|
|
218
|
-
const rc = this.
|
|
220
|
+
const rc = this.fnEmbed(this.handle, JSON.stringify({ input: text }), buf, buf.length);
|
|
219
221
|
if (rc !== 0) {
|
|
220
|
-
const err = this.
|
|
222
|
+
const err = this.fnLastError();
|
|
221
223
|
throw new Error(err || "embed failed");
|
|
222
224
|
}
|
|
223
225
|
return JSON.parse(buf.toString("utf8").replace(/\0+$/, ""));
|
|
224
226
|
}
|
|
225
227
|
transcribe(pcm) {
|
|
226
228
|
const buf = Buffer.alloc(1 << 16);
|
|
227
|
-
const rc = this.
|
|
229
|
+
const rc = this.fnTranscribe(this.handle, Buffer.from(pcm), pcm.length, null, buf, buf.length);
|
|
228
230
|
if (rc !== 0) {
|
|
229
|
-
const err = this.
|
|
231
|
+
const err = this.fnLastError();
|
|
230
232
|
throw new Error(err || "transcribe failed");
|
|
231
233
|
}
|
|
232
234
|
return buf.toString("utf8").replace(/\0+$/, "");
|
|
233
235
|
}
|
|
234
236
|
close() {
|
|
235
237
|
if (this.handle)
|
|
236
|
-
this.
|
|
238
|
+
this.fnDestroy(this.handle);
|
|
237
239
|
this.handle = null;
|
|
238
240
|
}
|
|
239
241
|
}
|