Skip to content

Fix wasm32 build and add load_encoding_from_bytes#100

Open
aliguori wants to merge 2 commits into
openai:mainfrom
aliguori:main
Open

Fix wasm32 build and add load_encoding_from_bytes#100
aliguori wants to merge 2 commits into
openai:mainfrom
aliguori:main

Conversation

@aliguori
Copy link
Copy Markdown

@aliguori aliguori commented Mar 3, 2026

The wasm32 code paths called load_encoding_from_bytes but the function was never defined, causing compilation failures when targeting wasm32. Add the missing function which parses tiktoken vocab data from a byte slice instead of a file path.

Also fix the wasm32 path in registry.rs which referenced a non-existent conversation_has_function_tools field on HarmonyEncoding.

Add load_harmony_encoding_from_vocab_bytes to allow constructing a HarmonyEncoding synchronously from embedded vocab bytes. This is needed for wasm32-unknown-unknown environments where neither filesystem access nor async HTTP are available.

Make Encoding::special_tokens() and Encoding::pattern() public so they can be used by load_harmony_encoding_from_vocab_bytes.

aliguori added 2 commits March 3, 2026 08:09
The wasm32 code paths called load_encoding_from_bytes but the
function was never defined, causing compilation failures when
targeting wasm32. Add the missing function which parses tiktoken
vocab data from a byte slice instead of a file path.

Also fix the wasm32 path in registry.rs which referenced a
non-existent conversation_has_function_tools field on
HarmonyEncoding.

Add load_harmony_encoding_from_vocab_bytes to allow constructing
a HarmonyEncoding synchronously from embedded vocab bytes. This
is needed for wasm32-unknown-unknown environments where neither
filesystem access nor async HTTP are available.

Make Encoding::special_tokens() and Encoding::pattern() public
so they can be used by load_harmony_encoding_from_vocab_bytes.
Add a 'network' feature (enabled by default) that gates reqwest and
image dependencies. This allows consumers that only need the
encoding/parsing functionality (e.g. WASM plugins using embedded
vocab bytes) to avoid pulling in reqwest, which brings wasm-bindgen
and JS interop code on wasm32 targets.

The load_harmony_encoding functions that download vocab files from
the network are gated behind the network feature. The
load_harmony_encoding_from_vocab_bytes function remains always
available since it operates on embedded bytes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant