Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wasm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ emcc "$SCRIPT_DIR/quant_wasm.c" \
-s MAXIMUM_MEMORY=4GB \
-s INITIAL_MEMORY=256MB \
-s EXPORTED_FUNCTIONS='["_main","_wasm_load_model","_wasm_generate","_wasm_generate_async","_wasm_model_info","_wasm_is_ready","_malloc","_free"]' \
-s EXPORTED_RUNTIME_METHODS='["UTF8ToString","allocateUTF8","FS"]' \
-s EXPORTED_RUNTIME_METHODS='["UTF8ToString","allocateUTF8","FS","ccall","cwrap"]' \
-s FORCE_FILESYSTEM=1 \
-s MODULARIZE=0 \
-s ENVIRONMENT=web \
Expand Down
20 changes: 16 additions & 4 deletions wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,22 @@ <h2>Run an <span>LLM</span> in your browser</h2>

await new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)));

const ptr = Module.allocateUTF8(getChatPrompt(text));
try { await Module._wasm_generate_async(ptr, 0.7, 256); }
catch(e) { Module._wasm_generate(ptr, 0.7, 256); }
Module._free(ptr);
const prompt = getChatPrompt(text);

// Use ccall with async:true — this is the correct way to call
// ASYNCIFY-enabled C functions. Module._fn() direct calls do NOT
// return Promises; only ccall({async:true}) does.
try {
await Module.ccall(
'wasm_generate_async',
'number',
['string', 'number', 'number'],
[prompt, 0.7, 256],
{ async: true }
);
} catch(e) {
console.error('generate error:', e);
}

if (!output && !count) {
aDiv.innerHTML = '<em style="color:#555">No output. Try a different prompt.</em>';
Expand Down
2 changes: 1 addition & 1 deletion wasm/quant.js

Large diffs are not rendered by default.

Binary file modified wasm/quant.wasm
Binary file not shown.
Loading