LMM natively targets wasm32-unknown-unknown. Because the HTTP client (reqwest) automatically switches to the browser fetch API on WASM targets, you can deploy LMM inside Rust frontend frameworks without any additional glue code.
LMM WASM integration is actively used and tested with:
- Yew: the most popular Rust / WASM frontend framework
- Dioxus: cross-platform Rust UI framework
- Leptos: fine-grained reactive framework
Add lmm to your Cargo.toml with the appropriate feature set. Avoid enabling rust-binary, python, or node on WASM targets.
[dependencies]
lmm = { version = "0.2.8", default-features = false, features = ["wasm-net"] }Build with Trunk (Yew / Leptos):
trunk serveDuckDuckGo's endpoints set permissive CORS headers on most responses, but the behaviour can vary by endpoint and region. If you encounter CORS errors:
- Use a server-side proxy to forward requests from your own origin.
- Use the
wt-wt(worldwide) region which tends to have the broadest CORS coverage. - Consider caching results server-side and serving them from your own API.
| Feature | WASM-safe | Description |
|---|---|---|
| (default) | ✅ | Core symbolic engine (no networking) |
wasm-net |
✅ | Enables reqwest fetch-based HTTP on WASM |
net |
❌ | Native Tokio networking: incompatible with WASM |
rust-binary |
❌ | CLI binary: incompatible with WASM |
python |
❌ | pyo3 bindings: incompatible with WASM |
node |
❌ | napi bindings: incompatible with WASM |
use lmm::prelude::*;
use yew::prelude::*;
#[function_component(PredictorDemo)]
fn predictor_demo() -> Html {
let output = use_state(|| String::from("Click to generate..."));
let onclick = {
let output = output.clone();
Callback::from(move |_| {
let predictor = TextPredictor::new(20, 30, 3);
if let Ok(result) = predictor.predict_continuation("Wise AI built the first LMM", 80) {
output.set(result.continuation);
}
})
};
html! {
<div>
<button {onclick}>{ "Generate" }</button>
<p>{ (*output).clone() }</p>
</div>
}
}Licensed under the MIT License.