@ariacompute/engine-ts 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/README.md +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +75 -0
- package/package.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @ariacompute/engine-ts
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
export ARIA_FFI_LIB=/path/to/libaria_ffi.so
|
|
5
|
+
npm i @ariacompute/engine-ts
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { Engine } from "@ariacompute/engine-ts";
|
|
10
|
+
const eng = new Engine("/path/to/bundle");
|
|
11
|
+
console.log(eng.complete([{ role: "user", content: "hi" }]));
|
|
12
|
+
eng.close();
|
|
13
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ChatMessage = {
|
|
2
|
+
role: string;
|
|
3
|
+
content: string;
|
|
4
|
+
};
|
|
5
|
+
export declare class Engine {
|
|
6
|
+
private lib;
|
|
7
|
+
private handle;
|
|
8
|
+
constructor(bundlePath: string);
|
|
9
|
+
close(): void;
|
|
10
|
+
complete(messages: ChatMessage[], options?: Record<string, unknown>, tools?: unknown[]): any;
|
|
11
|
+
embed(input: string): any;
|
|
12
|
+
transcribe(pcm: Buffer): any;
|
|
13
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Engine = void 0;
|
|
7
|
+
const koffi_1 = __importDefault(require("koffi"));
|
|
8
|
+
function loadLib() {
|
|
9
|
+
const path = process.env.ARIA_FFI_LIB;
|
|
10
|
+
if (!path)
|
|
11
|
+
throw new Error("Set ARIA_FFI_LIB");
|
|
12
|
+
const lib = koffi_1.default.load(path);
|
|
13
|
+
return {
|
|
14
|
+
init: lib.func("aria_model_init", "void *", ["str"]),
|
|
15
|
+
destroy: lib.func("aria_model_destroy", "void", ["void *"]),
|
|
16
|
+
complete: lib.func("aria_complete", "int", [
|
|
17
|
+
"void *",
|
|
18
|
+
"str",
|
|
19
|
+
"str",
|
|
20
|
+
"str",
|
|
21
|
+
"uint8 *",
|
|
22
|
+
"size_t",
|
|
23
|
+
]),
|
|
24
|
+
embed: lib.func("aria_embed", "int", ["void *", "str", "uint8 *", "size_t"]),
|
|
25
|
+
transcribe: lib.func("aria_transcribe", "int", [
|
|
26
|
+
"void *",
|
|
27
|
+
"uint8 *",
|
|
28
|
+
"size_t",
|
|
29
|
+
"str",
|
|
30
|
+
"uint8 *",
|
|
31
|
+
"size_t",
|
|
32
|
+
]),
|
|
33
|
+
lastError: lib.func("aria_last_error", "str", []),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function parseOut(buf) {
|
|
37
|
+
const text = buf.toString("utf8").replace(/\0.*$/s, "");
|
|
38
|
+
return JSON.parse(text);
|
|
39
|
+
}
|
|
40
|
+
class Engine {
|
|
41
|
+
constructor(bundlePath) {
|
|
42
|
+
this.lib = loadLib();
|
|
43
|
+
this.handle = this.lib.init(bundlePath);
|
|
44
|
+
if (!this.handle)
|
|
45
|
+
throw new Error(this.lib.lastError() || "init failed");
|
|
46
|
+
}
|
|
47
|
+
close() {
|
|
48
|
+
if (this.handle) {
|
|
49
|
+
this.lib.destroy(this.handle);
|
|
50
|
+
this.handle = null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
complete(messages, options = { max_tokens: 16 }, tools = []) {
|
|
54
|
+
const out = Buffer.alloc(256 * 1024);
|
|
55
|
+
const rc = this.lib.complete(this.handle, JSON.stringify(messages), JSON.stringify(options), JSON.stringify(tools), out, out.length);
|
|
56
|
+
if (rc !== 0)
|
|
57
|
+
throw new Error(this.lib.lastError() || "complete failed");
|
|
58
|
+
return parseOut(out);
|
|
59
|
+
}
|
|
60
|
+
embed(input) {
|
|
61
|
+
const out = Buffer.alloc(256 * 1024);
|
|
62
|
+
const rc = this.lib.embed(this.handle, JSON.stringify({ input }), out, out.length);
|
|
63
|
+
if (rc !== 0)
|
|
64
|
+
throw new Error(this.lib.lastError() || "embed failed");
|
|
65
|
+
return parseOut(out);
|
|
66
|
+
}
|
|
67
|
+
transcribe(pcm) {
|
|
68
|
+
const out = Buffer.alloc(64 * 1024);
|
|
69
|
+
const rc = this.lib.transcribe(this.handle, pcm, pcm.length, null, out, out.length);
|
|
70
|
+
if (rc !== 0)
|
|
71
|
+
throw new Error(this.lib.lastError() || "transcribe failed");
|
|
72
|
+
return parseOut(out);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.Engine = Engine;
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ariacompute/engine-ts",
|
|
3
|
+
"version": "1.4.1",
|
|
4
|
+
"description": "TypeScript/Node SDK for Aria Engine",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc -p .",
|
|
9
|
+
"test": "node --test test/binding.test.mjs"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"koffi": "^2.8.0"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "^20.11.0",
|
|
17
|
+
"typescript": "^5.4.0"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
]
|
|
23
|
+
}
|