From e82460b93edae6679d626259e4b4e8ab638daeb6 Mon Sep 17 00:00:00 2001 From: zoollcar Date: Thu, 14 Nov 2024 16:34:09 +0800 Subject: [PATCH] add mobile model --- src/App.tsx | 6 +++--- src/models/llm/LLMChatWebLLM.ts | 19 +++++++++++-------- src/models/tts/textToSpeech.ts | 1 - 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index e6b6d97..74d733f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -246,16 +246,16 @@ function App() { if (chat instanceof LLMChatWebLLM) { if (chat.getInitStatus() === "not start") { const answer = confirm( - "webLLM need to load at every time, first time may need some time to download model(~1.5G). load now?" + "webLLM need to load every time, first time need some time to download model(~1.5G(PC)/~800MB(phone)). load now?" ); if (answer) { const timer = setInterval(() => { setSubtitle(chat.initProgress || "webLLM loading"); }, 1000); chat.init().then(() => { - alert("webLLM loaded"); clearInterval(timer); - setSubtitle(""); + if (chat.getInitStatus() === "done") setSubtitle("webLLM loaded"); + else setSubtitle("webLLM error"); }); } return; diff --git a/src/models/llm/LLMChatWebLLM.ts b/src/models/llm/LLMChatWebLLM.ts index ab041ba..c63c91a 100644 --- a/src/models/llm/LLMChatWebLLM.ts +++ b/src/models/llm/LLMChatWebLLM.ts @@ -24,21 +24,24 @@ export default class LLMChatWebLLM { async init() { // This is an asynchronous call and can take a long time to finish + // models are https://github.com/mlc-ai/web-llm/blob/main/src/config.ts this.initStatus = "working"; - const maxStorageBufferBindingSize = - await this.client.getMaxStorageBufferBindingSize(); - console.log(maxStorageBufferBindingSize); - let selectedModel = "RedPajama-INCITE-Chat-3B-v1-q4f16_1-1k"; - if (maxStorageBufferBindingSize >= 2147480000) { - // ~2G - selectedModel = "Llama-3.2-3B-Instruct-q4f16_1-MLC"; - } try { + const maxStorageBufferBindingSize = + await this.client.getMaxStorageBufferBindingSize(); + // alert(maxStorageBufferBindingSize); + let selectedModel = "SmolLM2-135M-Instruct-q0f32-MLC"; + if (maxStorageBufferBindingSize >= 1073741800) { + // ~1G + selectedModel = "Llama-3.2-3B-Instruct-q4f16_1-MLC"; + } + console.log(`webLLM: select ${selectedModel}`); await this.client.reload(selectedModel); this.initStatus = "done"; } catch (e) { this.initStatus = "error"; this.initProgress = (e as Error).message; + alert("Error: " + (e as Error).message); } } diff --git a/src/models/tts/textToSpeech.ts b/src/models/tts/textToSpeech.ts index a45b95a..5ea135f 100644 --- a/src/models/tts/textToSpeech.ts +++ b/src/models/tts/textToSpeech.ts @@ -1,6 +1,5 @@ import { getBackendEndpoint } from "../appstore"; -// const vitsWebWorker = new Worker("./vitsWeb"); const vitsWebWorker = new Worker(new URL("./vitsWeb.ts", import.meta.url), { type: "module", // Specify that the worker is a module });