Fix wasm32 build and add load_encoding_from_bytes#100
Open
aliguori wants to merge 2 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.