@trymirai/uzu 0.1.2
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 +38 -0
- package/package.json +39 -0
- package/uzu.d.ts +205 -0
- package/uzu.node +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# TS Example (N-API)
|
|
2
|
+
|
|
3
|
+
This folder shows the *minimal* way to call the Rust crate **uzu_plus** from Node via the [`napi-rs`](https://github.com/napi-rs/napi-rs) tool-chain.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
## Prerequisites
|
|
7
|
+
|
|
8
|
+
1. **Rust** tool-chain (stable)
|
|
9
|
+
```bash
|
|
10
|
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
11
|
+
```
|
|
12
|
+
2. **Node.js**
|
|
13
|
+
```bash
|
|
14
|
+
brew install node
|
|
15
|
+
```
|
|
16
|
+
3. **pnpm** package manager –
|
|
17
|
+
```bash
|
|
18
|
+
brew install pnpm
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
> On macOS you may also need Xcode Command-Line Tools (`xcode-select --install`) because `cargo` builds a native library.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
## Getting started
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 1 / Install TS dependencies (installs @napi-rs/cli locally)
|
|
28
|
+
cd bindings/ts
|
|
29
|
+
pnpm install
|
|
30
|
+
|
|
31
|
+
# 2 / Build the native addon in release mode
|
|
32
|
+
pnpm run build
|
|
33
|
+
|
|
34
|
+
# 3 / Set your API key in `examples/api_key.ts`, then run the examples
|
|
35
|
+
pnpm run chat
|
|
36
|
+
pnpm run summarize
|
|
37
|
+
pnpm run classify
|
|
38
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trymirai/uzu",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "uzu.node",
|
|
6
|
+
"types": "uzu.d.ts",
|
|
7
|
+
"packageManager": "pnpm@10.14.0",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "./build.sh",
|
|
10
|
+
"chat": "ts-node examples/chat_example.ts",
|
|
11
|
+
"summarize": "ts-node examples/summarization_example.ts",
|
|
12
|
+
"classify": "ts-node examples/classification_example.ts"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@napi-rs/cli": "3.1.2",
|
|
16
|
+
"@types/node": "24.2.0",
|
|
17
|
+
"ts-node": "10.9.2",
|
|
18
|
+
"typescript": "5.9.2",
|
|
19
|
+
"@types/progress": "2.0.7"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"progress": "2.0.3"
|
|
23
|
+
},
|
|
24
|
+
"napi": {
|
|
25
|
+
"binaryName": "uzu"
|
|
26
|
+
},
|
|
27
|
+
"os": [
|
|
28
|
+
"darwin"
|
|
29
|
+
],
|
|
30
|
+
"cpu": [
|
|
31
|
+
"arm64"
|
|
32
|
+
],
|
|
33
|
+
"files": [
|
|
34
|
+
"uzu.node",
|
|
35
|
+
"uzu.d.ts",
|
|
36
|
+
"package.json",
|
|
37
|
+
"README.md"
|
|
38
|
+
]
|
|
39
|
+
}
|
package/uzu.d.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export declare class DownloadHandle {
|
|
4
|
+
start(): void
|
|
5
|
+
pause(): void
|
|
6
|
+
resume(): void
|
|
7
|
+
stop(): void
|
|
8
|
+
delete(): void
|
|
9
|
+
state(): ModelDownloadState
|
|
10
|
+
identifier(): string
|
|
11
|
+
progress(): AsyncIterable<ProgressUpdate>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Thin FFI wrapper around `ModelStorage`. */
|
|
15
|
+
export declare class Engine {
|
|
16
|
+
/** Returns a `DownloadHandle` for the given model identifier. */
|
|
17
|
+
downloadHandle(identifier: string): DownloadHandle
|
|
18
|
+
getModels(): Array<Model>
|
|
19
|
+
getState(identifier: string): ModelDownloadState
|
|
20
|
+
download(identifier: string): void
|
|
21
|
+
pause(identifier: string): void
|
|
22
|
+
resume(identifier: string): void
|
|
23
|
+
stop(identifier: string): void
|
|
24
|
+
delete(identifier: string): void
|
|
25
|
+
updateRegistry(): Promise<Array<Model>>
|
|
26
|
+
activate(apiKey: string): Promise<LicenseStatus>
|
|
27
|
+
constructor()
|
|
28
|
+
createSession(modelId: string): Session
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export declare class ProgressStream {
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export declare class ProgressUpdate {
|
|
36
|
+
/** Bytes downloaded so far. */
|
|
37
|
+
completedBytes: number
|
|
38
|
+
/** Total bytes expected for the download; `None` while unknown. */
|
|
39
|
+
totalBytes?: number
|
|
40
|
+
/** Normalised progress between 0.0 and 1.0. */
|
|
41
|
+
progress: number
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export declare class Session {
|
|
45
|
+
constructor(modelDir: string)
|
|
46
|
+
/** Loads the model configuration. Must be called before `run`. */
|
|
47
|
+
load(config: SessionConfig): void
|
|
48
|
+
run(input: SessionInput, runConfig: SessionRunConfig, progressCallback?: (arg: SessionOutput) => boolean | undefined | null): SessionOutput
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type ContextLength =
|
|
52
|
+
| { type: 'Default' }
|
|
53
|
+
| { type: 'Custom', length: number }
|
|
54
|
+
|
|
55
|
+
export interface DecoderTestResult {
|
|
56
|
+
placementLog: string
|
|
57
|
+
iterations: number
|
|
58
|
+
timePerToken: number
|
|
59
|
+
tokensPerSecond: number
|
|
60
|
+
success: boolean
|
|
61
|
+
error?: string
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type DownloaderError =
|
|
65
|
+
| { type: 'Http', message: string }
|
|
66
|
+
| { type: 'Io', message: string }
|
|
67
|
+
| { type: 'AlreadyExists', path: string }
|
|
68
|
+
| { type: 'Generic', message: string }
|
|
69
|
+
|
|
70
|
+
export type LicenseStatus =
|
|
71
|
+
| { type: 'NotActivated' }
|
|
72
|
+
| { type: 'PaymentRequired' }
|
|
73
|
+
| { type: 'GracePeriodActive' }
|
|
74
|
+
| { type: 'Activated' }
|
|
75
|
+
| { type: 'NetworkError' }
|
|
76
|
+
| { type: 'InvalidApiKey' }
|
|
77
|
+
| { type: 'SignatureMismatch' }
|
|
78
|
+
| { type: 'Timeout' }
|
|
79
|
+
| { type: 'HttpError', code: number }
|
|
80
|
+
|
|
81
|
+
export interface Model {
|
|
82
|
+
/** Unique identifier of the model in the form `<vendor>-<name>-<precision>`. */
|
|
83
|
+
readonly identifier: string
|
|
84
|
+
/** Vendor/author of the model (e.g. "Llama"). */
|
|
85
|
+
readonly vendor: string
|
|
86
|
+
/** Human-readable model name without vendor/precision (e.g. "3B-Instruct"). */
|
|
87
|
+
readonly name: string
|
|
88
|
+
/** Numerical precision of the weights (e.g. "float16"). */
|
|
89
|
+
readonly precision: string
|
|
90
|
+
/** Quantization type if the model is quantized (e.g. "uint4"). */
|
|
91
|
+
readonly quantization?: string
|
|
92
|
+
/** Current download/installation state. */
|
|
93
|
+
readonly state: ModelDownloadState
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface ModelDownloadState {
|
|
97
|
+
/** Total size of all model files in kilobytes. */
|
|
98
|
+
readonly totalKbytes: number
|
|
99
|
+
/** Bytes already downloaded (meaningful in Downloading / Paused). */
|
|
100
|
+
readonly downloadedKbytes: number
|
|
101
|
+
/** Current phase of the download. */
|
|
102
|
+
readonly phase: Phase
|
|
103
|
+
/** Stringified error when `phase == Phase::Error`. */
|
|
104
|
+
readonly error?: string
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export declare const enum Phase {
|
|
108
|
+
NotDownloaded = 0,
|
|
109
|
+
Downloading = 1,
|
|
110
|
+
Paused = 2,
|
|
111
|
+
Downloaded = 3,
|
|
112
|
+
Error = 4
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type SamplingConfig =
|
|
116
|
+
| { type: 'Argmax' }
|
|
117
|
+
| { type: 'TopP', topP: number }
|
|
118
|
+
| { type: 'Categorical', temperature: number }
|
|
119
|
+
|
|
120
|
+
export type SamplingSeed =
|
|
121
|
+
| { type: 'Default' }
|
|
122
|
+
| { type: 'Custom', seed: number }
|
|
123
|
+
|
|
124
|
+
export interface SessionClassificationFeature {
|
|
125
|
+
name: string
|
|
126
|
+
values: Array<string>
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface SessionConfig {
|
|
130
|
+
preset: SessionPreset
|
|
131
|
+
samplingSeed: SamplingSeed
|
|
132
|
+
contextLength: ContextLength
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type SessionInput =
|
|
136
|
+
| { type: 'Text', text: string }
|
|
137
|
+
| { type: 'Messages', messages: Array<SessionMessage> }
|
|
138
|
+
|
|
139
|
+
export interface SessionMessage {
|
|
140
|
+
role: SessionMessageRole
|
|
141
|
+
content: string
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export declare const enum SessionMessageRole {
|
|
145
|
+
System = 0,
|
|
146
|
+
User = 1,
|
|
147
|
+
Assistant = 2
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface SessionOutput {
|
|
151
|
+
text: string
|
|
152
|
+
stats: SessionOutputStats
|
|
153
|
+
finishReason?: SessionOutputFinishReason
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export declare const enum SessionOutputFinishReason {
|
|
157
|
+
Stop = 0,
|
|
158
|
+
Length = 1,
|
|
159
|
+
Cancelled = 2
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface SessionOutputRunStats {
|
|
163
|
+
count: bigint
|
|
164
|
+
averageDuration: number
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface SessionOutputStats {
|
|
168
|
+
prefillStats: SessionOutputStepStats
|
|
169
|
+
generateStats?: SessionOutputStepStats
|
|
170
|
+
totalStats: SessionOutputTotalStats
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface SessionOutputStepStats {
|
|
174
|
+
duration: number
|
|
175
|
+
suffixLength: bigint
|
|
176
|
+
tokensCount: bigint
|
|
177
|
+
tokensPerSecond: number
|
|
178
|
+
modelRun: SessionOutputRunStats
|
|
179
|
+
run?: SessionOutputRunStats
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface SessionOutputTotalStats {
|
|
183
|
+
duration: number
|
|
184
|
+
tokensCountInput: bigint
|
|
185
|
+
tokensCountOutput: bigint
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export type SessionPreset =
|
|
189
|
+
| { type: 'General' }
|
|
190
|
+
| { type: 'Classification', field0: SessionClassificationFeature }
|
|
191
|
+
| { type: 'Summarization' }
|
|
192
|
+
|
|
193
|
+
export interface SessionRunConfig {
|
|
194
|
+
tokensLimit: number
|
|
195
|
+
samplingConfig?: SamplingConfig
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export type StorageError =
|
|
199
|
+
| { type: 'ModelNotDownloaded' }
|
|
200
|
+
| { type: 'UnknownModel', identifier: string }
|
|
201
|
+
| { type: 'Storage', message: string }
|
|
202
|
+
| { type: 'MutexPoisoned', message: string }
|
|
203
|
+
| { type: 'LicenseNotActivated' }
|
|
204
|
+
|
|
205
|
+
export declare function version(): string
|
package/uzu.node
ADDED
|
Binary file
|