chore: import upstream snapshot with attribution
Build / build (push) Has been cancelled
Tests / test (push) Has been cancelled
Build site and push to gh-pages / Build site (push) Has been cancelled
Linter / lint (push) Has been cancelled
Security / dependency-review (push) Has been cancelled
Security / npm-audit (push) Has been cancelled
Security / codeql (push) Has been cancelled
Build / build (push) Has been cancelled
Tests / test (push) Has been cancelled
Build site and push to gh-pages / Build site (push) Has been cancelled
Linter / lint (push) Has been cancelled
Security / dependency-review (push) Has been cancelled
Security / npm-audit (push) Has been cancelled
Security / codeql (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<script>
|
||||
webLLMGlobal = {};
|
||||
</script>
|
||||
<body>
|
||||
<h2>WebLLM Test Page</h2>
|
||||
Open console to see output
|
||||
<br />
|
||||
<br />
|
||||
<label id="init-label"> </label>
|
||||
|
||||
<h3>Prompt</h3>
|
||||
<label id="prompt-label"> </label>
|
||||
|
||||
<h3>Response</h3>
|
||||
<label id="generate-label"> </label>
|
||||
<br />
|
||||
<label id="stats-label"> </label>
|
||||
|
||||
<script type="module" src="./text_completion.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,58 @@
|
||||
import * as webllm from "@mlc-ai/web-llm";
|
||||
|
||||
function setLabel(id: string, text: string) {
|
||||
const label = document.getElementById(id);
|
||||
if (label == null) {
|
||||
throw Error("Cannot find label " + id);
|
||||
}
|
||||
label.innerText = text;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const initProgressCallback = (report: webllm.InitProgressReport) => {
|
||||
setLabel("init-label", report.text);
|
||||
};
|
||||
|
||||
// Unlike "Llama-3.1-8B-Instruct-q4f32_1-MLC", this is a base model
|
||||
const selectedModel = "Llama-3.1-8B-q4f32_1-MLC";
|
||||
|
||||
const appConfig: webllm.AppConfig = {
|
||||
model_list: [
|
||||
{
|
||||
model: "https://huggingface.co/mlc-ai/Llama-3.1-8B-q4f32_1-MLC", // a base model
|
||||
model_id: selectedModel,
|
||||
model_lib:
|
||||
webllm.modelLibURLPrefix +
|
||||
webllm.modelVersion +
|
||||
"/Llama-3_1-8B-Instruct-q4f32_1-ctx4k_cs1k-webgpu.wasm",
|
||||
overrides: {
|
||||
context_window_size: 2048,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
const engine: webllm.MLCEngineInterface = await webllm.CreateMLCEngine(
|
||||
selectedModel,
|
||||
{
|
||||
appConfig: appConfig,
|
||||
initProgressCallback: initProgressCallback,
|
||||
logLevel: "INFO",
|
||||
},
|
||||
);
|
||||
|
||||
const reply0 = await engine.completions.create({
|
||||
prompt: "List 3 US states: ",
|
||||
// below configurations are all optional
|
||||
echo: true,
|
||||
n: 2,
|
||||
max_tokens: 64,
|
||||
logprobs: true,
|
||||
top_logprobs: 2,
|
||||
});
|
||||
console.log(reply0);
|
||||
console.log(reply0.usage);
|
||||
|
||||
// To change model, either create a new engine via `CreateMLCEngine()`, or call `engine.reload(modelId)`
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user