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
12 changes: 2 additions & 10 deletions examples/chrome-extension-webgpu-service-worker/src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import './popup.css';

import { ChatModule, AppConfig, InitProgressReport } from "@mlc-ai/web-llm";
import { prebuiltAppConfig } from '@mlc-ai/web-llm';
import { ProgressBar, Line } from "progressbar.js";

// Whether or not to use the content from the active tab as the context
Expand Down Expand Up @@ -35,16 +36,7 @@ var progressBar: ProgressBar = new Line('#loadingContainer', {
svgStyle: { width: '100%', height: '100%' }
});

const appConfig: AppConfig = {
model_list: [
{
"model_url": "https://huggingface.co/mlc-ai/Mistral-7B-Instruct-v0.2-q4f16_1-MLC/resolve/main/",
"model_id": "Mistral-7B-Instruct-v0.2-q4f16_1",
"model_lib_url": "https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",
"required_features": ["shader-f16"],
}
]
}
const appConfig: AppConfig = prebuiltAppConfig;

chrome.runtime.sendMessage({ reload: appConfig });
chrome.runtime.onMessage.addListener(function (request) {
Expand Down
13 changes: 1 addition & 12 deletions examples/chrome-extension/src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,6 @@ if (useWebGPU) {
svgStyle: { width: '100%', height: '100%' }
});

const appConfig: AppConfig = {
model_list: [
{
"model_url": "https://huggingface.co/mlc-ai/Mistral-7B-Instruct-v0.2-q4f16_1-MLC/resolve/main/",
"model_id": "Mistral-7B-Instruct-v0.2-q4f16_1",
"model_lib_url": "https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",
"required_features": ["shader-f16"],
}
]
}

cm.setInitProgressCallback((report: InitProgressReport) => {
console.log(report.text, report.progress);
progressBar.animate(report.progress, {
Expand All @@ -62,7 +51,7 @@ if (useWebGPU) {
}
});

await cm.reload("Mistral-7B-Instruct-v0.2-q4f16_1", undefined, appConfig);
await cm.reload("Mistral-7B-Instruct-v0.2-q4f16_1");

isLoadingParams = true;
} else {
Expand Down
18 changes: 1 addition & 17 deletions examples/get-started/src/get_started.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,9 @@ async function main() {
});

// Option 1: Specify appConfig to decide what models to include
const myAppConfig: webllm.AppConfig = {
model_list: [
{
"model_url": "https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f32_1-MLC/resolve/main/",
"model_id": "Llama-2-7b-chat-hf-q4f32_1",
"model_lib_url": "https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f32_1-ctx4k_cs1k-webgpu.wasm",
},
{
"model_url": "https://huggingface.co/mlc-ai/Mistral-7B-Instruct-v0.2-q4f16_1-MLC/resolve/main/",
"model_id": "Mistral-7B-Instruct-v0.2-q4f16_1",
"model_lib_url": "https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",
"required_features": ["shader-f16"],
},
// Add your own models here...
]
}
const selectedModel = "Llama-2-7b-chat-hf-q4f32_1"
// const selectedModel = "Mistral-7B-Instruct-v0.2-q4f16_1"
await chat.reload(selectedModel, undefined, myAppConfig);
await chat.reload(selectedModel);

// Option 2: If we do not specify appConfig, we use `prebuiltAppConfig` defined in `config.ts`
// await chat.reload("Llama-2-7b-chat-hf-q4f32_1");
Expand Down
13 changes: 1 addition & 12 deletions examples/logit-processor/src/logit_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ function setLabel(id: string, text: string) {
}

async function main() {
// Define modelRecord
const myAppConfig: webllm.AppConfig = {
model_list: [
{
"model_url": "https://huggingface.co/mlc-ai/phi-2-q4f32_1-MLC/resolve/main/",
"model_id": "Phi2-q4f32_1",
"model_lib_url": "https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/phi-2/phi-2-q4f32_1-ctx2k-webgpu.wasm",
},
]
}

// Instantiate myLogitProcessor, registering in the logitProcessorRegistry
const myLogitProcessor = new MyLogitProcessor();
const logitProcessorRegistry = new Map<string, webllm.LogitProcessor>();
Expand All @@ -47,7 +36,7 @@ async function main() {
});

// Reload chat module with a logit processor
await chat.reload("Phi2-q4f32_1", undefined, myAppConfig);
await chat.reload("Phi2-q4f32_1");

// Below we demonstrate the usage of a low-level API `forwardTokensAndSample()`
const prompt: Array<number> = [42];
Expand Down
18 changes: 9 additions & 9 deletions tests/function_calling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Test conversation template', () => {
const conv = getConversation("gorilla");
conv.appendMessage(Role.user, "Call me an Uber ride type \"Plus\" in Berkeley at zipcode 94704 in 10 minutes", "Tom");
const prompt_array = conv.getPromptArray();

expect(prompt_array).toEqual([
"A chat between a curious user and an artificial intelligence assistant. " +
"The assistant gives helpful, detailed, and polite answers to the user's questions.\n",
Expand All @@ -26,14 +26,14 @@ describe('Test conversation template', () => {
"name": "Uber Carpool",
"api_name": "uber.ride",
"description": "Find suitable ride for customers given the location, type of ride, and the amount of time the customer is willing to wait as parameters",
"parameters": [
{"name": "loc", "description": "Location of the starting place of the Uber ride"},
{"name": "type", "enum": ["plus", "comfort", "black"], "description": "Types of Uber ride user is ordering"},
{"name": "time", "description": "The amount of time in minutes the customer is willing to wait"}
"parameters": [
{ "name": "loc", "description": "Location of the starting place of the Uber ride" },
{ "name": "type", "enum": ["plus", "comfort", "black"], "description": "Types of Uber ride user is ordering" },
{ "name": "time", "description": "The amount of time in minutes the customer is willing to wait" }
]
}]);
const prompt_array = conv.getPromptArray();

expect(prompt_array).toEqual([
"A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\n",
"USER: <<question>> Call me an Uber ride type \"Plus\" in Berkeley at zipcode 94704 in 10 minutes <<function>> [{\"name\":\"Uber Carpool\",\"api_name\":\"uber.ride\",\"description\":\"Find suitable ride for customers given the location, type of ride, and the amount of time the customer is willing to wait as parameters\",\"parameters\":[{\"name\":\"loc\",\"description\":\"Location of the starting place of the Uber ride\"},{\"name\":\"type\",\"enum\":[\"plus\",\"comfort\",\"black\"],\"description\":\"Types of Uber ride user is ordering\"},{\"name\":\"time\",\"description\":\"The amount of time in minutes the customer is willing to wait\"}]}]\n"
Expand All @@ -53,9 +53,9 @@ describe('Test ChatModule', () => {
],
tool_choice: 'none',
tools: [
{ type: 'function', function: { description: 'A', name: 'fn_A', parameters: { foo: 'bar' } } },
{ type: 'function', function: { description: 'B', name: 'fn_B', parameters: { foo: 'bar' } } },
{ type: 'function', function: { description: 'C', name: 'fn_C', parameters: { foo: 'bar' } } },
{ type: 'function', function: { description: 'A', name: 'fn_A', parameters: { foo: 'bar' } } },
{ type: 'function', function: { description: 'B', name: 'fn_B', parameters: { foo: 'bar' } } },
{ type: 'function', function: { description: 'C', name: 'fn_C', parameters: { foo: 'bar' } } },
],
};

Expand Down