Public
Edited
Jan 24
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
getWebLLMCompletionStream(webllmParams.systemPrompt, webllmParams.prompt, {
temperature: webllmParams.temperature,
model: webllmParams.model
})
Insert cell
Insert cell
webllm = import("https://esm.run/@mlc-ai/web-llm@0.2.78")
Insert cell
availableModels = webllm.prebuiltAppConfig.model_list.map((m) => m.model_id)
Insert cell
engine = {
const setLabel = (id, text) => {
const label = document.getElementById(id);
if (label == null) {
throw Error("Cannot find label " + id);
}
label.innerText = text;
};

const initProgressCallback = (report) => {
setLabel("model-load", report.text);
};

return webllm.CreateMLCEngine(selectedModel, {
initProgressCallback: initProgressCallback
});
}
Insert cell
async function getWebLLMCompletionStream(
systemPrompt,
prompt,
{ temperature = 0.0 } = {}
) {
const outputElement = document.getElementById("webllm-output");
outputElement.textContent = "";

if (prompt.length == 0) {
return;
}

let messages = [];
if (systemPrompt) {
messages.push({ role: "system", content: systemPrompt });
}
messages.push({ role: "user", content: prompt });

const stream = await engine.chat.completions.create({
messages: messages,
temperature: temperature,
stream: true
});

for await (const part of stream) {
const text = part.choices[0]?.delta?.content || "";
outputElement.textContent += text;
}
}
Insert cell
import { guard } from "@mootari/inputs-submit"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more