Skip to content

Commit cfd3399

Browse files
khj809grf53
andauthored
Add wasm binding for values (#214)
Co-authored-by: grf53 <[email protected]>
1 parent 8a98e33 commit cfd3399

37 files changed

+1038
-1020
lines changed

Cargo.lock

Lines changed: 52 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v2/Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ python = [
2626
"dep:pyo3-async-runtimes",
2727
"dep:pyo3-stub-gen",
2828
"dep:pyo3-stub-gen-derive",
29-
"ailoy-model-cli",
3029
]
31-
nodejs = ["dep:napi", "dep:napi-derive", "ailoy-model-cli"]
30+
nodejs = ["dep:napi", "dep:napi-derive"]
31+
wasm = []
3232
ailoy-model-cli = ["dep:aws-config", "dep:aws-sdk-s3", "dep:clap", "dep:indicatif"]
3333
default = []
3434

@@ -54,10 +54,10 @@ jsonschema = { version = "0.33.0", default-features = false }
5454
mime-infer = "4.0.0"
5555
minijinja = { version = "2.11.0", features = ["loader", "custom_syntax", "json", "preserve_order"] }
5656
minijinja-contrib = { version = "2.11.0", features = ["pycompat"] }
57-
napi = { version = "3", features = ["tokio_rt", "napi8", "serde-json"], optional = true }
58-
napi-derive = { version = "3", optional = true }
57+
napi = { git = "https://github.com/brekkylab/napi-rs.git", package = "napi", rev = "5c8991b91072b5e468b1781de5703dc8449e000a", features = ["tokio_rt", "napi8", "serde-json"], optional = true }
58+
napi-derive = { git = "https://github.com/brekkylab/napi-rs.git", package = "napi-derive", rev = "5c8991b91072b5e468b1781de5703dc8449e000a", optional = true }
5959
ordered-float = { version = "5.0.0", features = ["serde"] }
60-
pyo3 = { version = "0.26", features = ["experimental-async", "macros"], optional = true }
60+
pyo3 = { version = "0.26", features = ["experimental-async", "macros", "anyhow"], optional = true }
6161
pyo3-async-runtimes = { version = "0.26", features = ["attributes", "tokio-runtime"], optional = true }
6262
pyo3-stub-gen = { version = "0.12.2", optional = true }
6363
pyo3-stub-gen-derive = { version = "0.12.2", optional = true }
@@ -88,6 +88,7 @@ js-sys = "0.3"
8888
sse-stream = "0.2"
8989
tokenizers = { version = "0.21.4", default-features = false, features = ["fancy-regex"] }
9090
tokio = { version = "1.0", default-features = false, features = ["macros", "rt", "sync"] }
91+
tsify = { version = "0.5.5", default-features = false, features = ["js"] }
9192
uuid = { version = "1.18.0", features = ["v4", "js"] }
9293
wasm-bindgen = "0.2"
9394
wasm-bindgen-futures = "0.4"

v2/bindings/nodejs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"main": "index.js",
55
"napi": {
66
"binaryName": "ailoy_core",
7-
"dtsHeaderFile": "./src/header.d.ts",
87
"targets": [
98
"x86_64-pc-windows-msvc",
109
"x86_64-unknown-linux-gnu",
1110
"aarch64-apple-darwin"
12-
]
11+
],
12+
"constEnum": false
1313
},
1414
"scripts": {
1515
"build:napi": "napi build --platform --release --package ailoy --features nodejs --manifest-path ../../../Cargo.toml --js ailoy_core.js --dts ailoy_core.d.ts --esm -o ./src && prettier -w ./src/ailoy_core.d.ts",

v2/bindings/nodejs/src/ailoy_core.d.ts

Lines changed: 49 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* auto-generated by NAPI-RS */
2+
/* eslint-disable */
13
export declare class LangModel {
24
static createLocal(
35
modelName: string,
@@ -19,14 +21,13 @@ export declare class LangModelRunIterator {
1921
next(): Promise<LanguageModelIteratorResult>;
2022
}
2123

22-
export declare const enum APISpecification {
23-
ChatCompletion = "ChatCompletion",
24-
OpenAI = "OpenAI",
25-
Gemini = "Gemini",
26-
Claude = "Claude",
27-
Responses = "Responses",
28-
Grok = "Grok",
29-
}
24+
export type APISpecification =
25+
| "ChatCompletion"
26+
| "OpenAI"
27+
| "Gemini"
28+
| "Claude"
29+
| "Responses"
30+
| "Grok";
3031

3132
export interface CacheProgress {
3233
comment: string;
@@ -35,24 +36,24 @@ export interface CacheProgress {
3536
}
3637

3738
export type FinishReason =
38-
| { type: "Stop" }
39-
| { type: "Length" }
40-
| { type: "ToolCall" }
41-
| { type: "Refusal"; field0: string };
39+
| { type: "stop" }
40+
| { type: "length" }
41+
| { type: "tool_call" }
42+
| { type: "refusal"; reason: string };
4243

4344
export type Grammar =
44-
| { type: "Plain" }
45-
| { type: "JSON" }
46-
| { type: "JSONSchema"; field0: string }
47-
| { type: "Regex"; field0: string }
48-
| { type: "CFG"; field0: string };
45+
| { type: "plain" }
46+
| { type: "json" }
47+
| { type: "jsonschema"; schema: string }
48+
| { type: "regex"; regex: string }
49+
| { type: "cfg"; cfg: string };
4950

5051
export interface InferenceConfig {
51-
thinkEffort: ThinkEffort;
52+
thinkEffort?: ThinkEffort;
5253
temperature?: number;
5354
topP?: number;
5455
maxTokens?: number;
55-
grammar: Grammar;
56+
grammar?: Grammar;
5657
}
5758

5859
export interface LanguageModelIteratorResult {
@@ -62,82 +63,71 @@ export interface LanguageModelIteratorResult {
6263

6364
export interface Message {
6465
role: Role;
65-
id?: string;
66-
thinking: string;
6766
contents: Array<Part>;
68-
toolCalls: Array<Part>;
67+
id?: string;
68+
thinking?: string;
69+
tool_calls?: Array<Part>;
6970
signature?: string;
7071
}
7172

7273
export interface MessageDelta {
7374
role?: Role;
7475
id?: string;
75-
thinking: string;
76+
thinking?: string;
7677
contents: Array<PartDelta>;
77-
toolCalls: Array<PartDelta>;
78+
tool_calls: Array<PartDelta>;
7879
signature?: string;
7980
}
8081

8182
export interface MessageOutput {
8283
delta: MessageDelta;
83-
finishReason?: FinishReason;
84+
finish_reason?: FinishReason;
8485
}
8586

8687
export type Part =
87-
| { type: "Text"; text: string }
88-
| { type: "Function"; id?: string; f: PartFunction }
89-
| { type: "Value"; value: any }
90-
| { type: "Image"; image: PartImage };
88+
| { type: "text"; text: string }
89+
| { type: "function"; id?: string; function: PartFunction }
90+
| { type: "value"; value: any }
91+
| { type: "image"; image: PartImage };
9192

9293
export type PartDelta =
93-
| { type: "Text"; text: string }
94-
| { type: "Function"; id?: string; f: PartDeltaFunction }
95-
| { type: "Value"; value: any }
96-
| { type: "Null" };
94+
| { type: "text"; text: string }
95+
| { type: "function"; id?: string; function: PartDeltaFunction }
96+
| { type: "value"; value: any }
97+
| { type: "null" };
9798

9899
export type PartDeltaFunction =
99-
| { type: "Verbatim"; field0: string }
100-
| { type: "WithStringArgs"; name: string; args: string }
101-
| { type: "WithParsedArgs"; name: string; args: any };
100+
| { type: "verbatim"; text: string }
101+
| { type: "with_string_args"; name: string; arguments: string }
102+
| { type: "with_parsed_args"; name: string; arguments: any };
102103

103104
export interface PartFunction {
104105
name: string;
105-
args: any;
106+
arguments: any;
106107
}
107108

108109
export type PartImage = {
109-
type: "Binary";
110-
h: number;
111-
w: number;
112-
c: PartImageColorspace;
110+
type: "binary";
111+
height: number;
112+
width: number;
113+
colorspace: PartImageColorspace;
113114
data: Buffer;
114115
};
115116

116-
export declare const enum PartImageColorspace {
117-
Grayscale = "Grayscale",
118-
RGB = "RGB",
119-
RGBA = "RGBA",
120-
}
117+
export type PartImageColorspace = "grayscale" | "rgb" | "rgba";
121118

122119
/** The author of a message (or streaming delta) in a chat. */
123-
export declare const enum Role {
120+
export type Role =
124121
/** System instructions and constraints provided to the assistant. */
125-
System = "System",
122+
| "system"
126123
/** Content authored by the end user. */
127-
User = "User",
124+
| "user"
128125
/** Content authored by the assistant/model. */
129-
Assistant = "Assistant",
126+
| "assistant"
130127
/** Outputs produced by external tools/functions */
131-
Tool = "Tool",
132-
}
128+
| "tool";
133129

134-
export declare const enum ThinkEffort {
135-
Disable = "Disable",
136-
Enable = "Enable",
137-
Low = "Low",
138-
Medium = "Medium",
139-
High = "High",
140-
}
130+
export type ThinkEffort = "disable" | "enable" | "low" | "medium" | "high";
141131

142132
export interface ToolDesc {
143133
name: string;

v2/bindings/nodejs/src/header.d.ts

Whitespace-only changes.

v2/bindings/nodejs/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"allowSyntheticDefaultImports": true,
1111
},
1212
"include": ["./src"],
13-
"exclude": ["node_modules", "./src/header.d.ts"]
13+
"exclude": ["node_modules"]
1414
}

0 commit comments

Comments
 (0)