rougail-ai/webllm/index.js.1

29 lines
727 B
Groff
Raw Permalink Normal View History

2026-09-14 21:22:34 +02:00
// import { CreateMLCEngine } from "@mlc-ai/web-llm";
import { CreateMLCEngine } from "./node_modules/@mlc-ai/web-llm/lib/index.js";
// Callback function to update model loading progress
const initProgressCallback = (initProgress) => {
console.log(initProgress);
};
const selectedModel = "Llama-3.1-8B-Instruct-q4f32_1-MLC";
const engine = await CreateMLCEngine(
selectedModel,
{ initProgressCallback: initProgressCallback }, // engineConfig
);
// chat
const messages = [
{ role: "system", content: "You are a helpful AI assistant." },
{ role: "user", content: "Hello!" },
];
const reply = await engine.chat.completions.create({
messages,
});
console.log(reply.choices[0].message);
console.log(reply.usage);