Upgrade to Pro — share decks privately, control downloads, hide ads and more …

aigame & webllm

oggata
February 24, 2025

aigame & webllm

oggata

February 24, 2025
Tweet

More Decks by oggata

Other Decks in Technology

Transcript

  1. MACHINE LEARNING COMPILATION(MLC) MACHINE LEARNING COMPILATION(MLC) https://www.cmu.edu/flame/research/2024/machine-learning-compilation-for-large-language-models.html CLI / Server

    mlc_llm serve Android MLC JVM iOS MLC Swift Web browser WebLLM webgpu + wasm ios android os AMD / Nvidia model-lib model compilation platform native runtime model weight mlc weight conversion pre-converted weight original model weight
  2. WEB LLM CHAT WEB LLM CHAT 新鮮なココナッツミルクを使ったカレーのレシピを紹介しよう: 材料 ココナッツオイル 大さじ2ニンニクのみじん切り

    大さじ2おろし ショウガ 大さじ2玉ねぎ(みじん切り)小1/2個青唐辛子 (種を取り除き、みじん切り) 2~3本ココナッツミルク(または アーモンドミルク、ココナッツミルク) 大さじ2~3塩 適量コリ アンダー、パセリ、コリアンダーなどのフレッシュハーブ 作り方 小鍋または中くらいの大きさの鍋にココナッツオイルを入れ、 よくかき混ぜながら中弱火で溶かす。 にんにく、しょうが、玉ねぎのみじん切りを加え、香りが出るま で2~3分炒める。 みじん切りにした青唐辛子を加え、1~2分炒める。 すりおろしたココナッツミルクを加え、炒めた材料を加える。 カレーを沸騰させたら弱火にし、鍋にふたをして、途中で混 ぜながら、とろみが少しついてココナッツミルクが泡立ち始 めるまで約10~12分煮る。 必要に応じて塩を加える。 お好みでフレッシュハーブを加え、さらに1~2分煮る。 温かいうちにご飯や麺と一緒に食べる。お好みでフレッシュ ライムジュースを添える。 フレッシュココナッツミルクとフレッシュハーブで作るカレーをお 楽しみください。
  3. import {ChatCompletionMessageParam, CreateMLCEngine, MLCEngine} from '@mlc-ai/web-llm'; const model = 'Llama-3.2-3B-Instruct-q4f32_1-MLC';

    this.engine = await CreateMLCEngine(model, { initProgressCallback: ({progress}) => this.progress.set(progress) }); this.ready.set(true); await this.engine!.resetChat(); const systemPrompt = ` The user will ask questions about their todo list. Here's the user's todo list: ${this.todos().map(todo => `* ${todo.text} (${todo.done ? 'done' : 'not done'})`).join('\n')}`; const messages: ChatCompletionMessageParam[] = [ {role: "system", content: systemPrompt}, {role: "user", content: userPrompt} ]; const chunks = await this.engine!.chat.completions.create({messages, stream: true}); let reply = ''; for await (const chunk of chunks) { reply += chunk.choices[0]?.delta.content ?? ''; this.reply.set(reply);