In WebLLM, models are managed via ModelRecord instances. There are two primary ways to initialize an engine with a model:
- Prebuilt Models: Use a
model_id that is already registered in webllm.prebuiltAppConfig.model_list. - Custom Models: Provide a custom
AppConfig containing a model_list of ModelRecord objects. Each record requires:model: A URL to the converted MLC model weights (e.g., a Hugging Face repository).model_id: A unique identifier for the model.model_lib: A URL to the compiled model library (typically a .wasm file) that contains the inference logic.
To run a custom model, pass the appConfig to webllm.CreateMLCEngine.
// Option 1: Using a prebuilt model
const selectedModel = "Llama-3-8B-Instruct-q4f32_1-MLC";
const engine = await webllm.CreateMLCEngine(selectedModel);
// Option 2: Using a custom model via AppConfig
const appConfig: webllm.AppConfig = {
model_list: [
{
model: "https://huggingface.co/mlc-ai/Llama-3-8B-Instruct-q4f32_1-MLC",
model_id: "Llama-3-8B-Instruct-q4f32_1-MLC",
model_lib: webllm.modelLibURLPrefix + webllm.modelVersion + "/Llama-3-8B-Instruct-q4f32_1-ctx4k_cs1k-webgpu.wasm",
},
],
};
const selectedModel = "Llama-3-8B-Instruct-q4f32_1-MLC";
const engine: webllm.MLCEngineInterface = await webllm.CreateMLCEngine(
selectedModel,
{ appConfig: appConfig },
);