Skip to content

feat: add AI model selection dropdown with per-model completion params - #248

Merged
ktjn merged 1 commit into
mainfrom
feat/add-model-selection
Jul 29, 2026
Merged

feat: add AI model selection dropdown with per-model completion params#248
ktjn merged 1 commit into
mainfrom
feat/add-model-selection

Conversation

@cjot

@cjot cjot commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a model selector dropdown to the assistant onboarding UI so users can choose which WebLLM model to download before clicking "Download AI model".

Changes

Model configuration (web/src/ai/webgpu-provider.ts)

  • New ModelOption interface with id, label, description, vramMb, and optional completionParams
  • AVAILABLE_MODELS array with two entries:
    • Qwen2.5 0.5B (default, ~945 MB VRAM) — the existing model, no behavioral change
    • Qwen3 1.7B (~2 GB VRAM) — includes completionParams: { extra_body: { enable_thinking: false } }
  • WebGPUProvider constructor now accepts ModelOption instead of a raw string
  • Passes completionParams through the AiWorkerRequest

Web Worker (web/src/ai/ai.worker.ts)

  • Stores completionParams on init, merges into every completion request via spread
  • Zero model-specific conditionals — adding a model with new params is one array entry

UI (web/src/ai/ChatPanel.tsx, web/src/App.tsx)

  • <select> dropdown shown in the onboarding section when status === 'idle'
  • selectedModel state in App.tsx, passed down as props
  • handleAiDownload looks up the matching ModelOption and passes it to new WebGpuProvider(config)

Styles (web/src/style.css)

  • .chat-model-select styled to match the existing button aesthetic

Testing

  • npm run check (tsc) — clean
  • npm test (vitest) — 353 passed, 4 pre-existing failures in App.test.tsx (missing assumptions in mock data, unrelated to these changes)
  • ruff format / ruff check — clean

@cjot
cjot requested a review from ktjn July 28, 2026 20:00
@cjot
cjot force-pushed the feat/add-model-selection branch from b906f36 to 509a09e Compare July 28, 2026 20:03
Add a model <select> dropdown alongside 'Download AI model' in the
chat onboarding UI. Models carry their own completionParams so the
worker has no model-specific branching.

Model configuration (webgpu-provider.ts):
- ModelOption type with id, label, description, vramMb, completionParams
- AVAILABLE_MODELS array: Qwen2.5-0.5B (~945 MB, default), Qwen3-1.7B (~2 GB)
- Qwen3-1.7B passes extra_body: { enable_thinking: false } automatically
- WebGPUProvider constructor accepts ModelOption instead of raw string

Web Worker (ai.worker.ts):
- Stores completionParams per-session, merged into every completion via spread
- Zero model-specific conditionals

UI (ChatPanel.tsx, App.tsx):
- <select> dropdown in onboarding when status === 'idle'
- selectedModel state wired through ChatPanel props to handleAiDownload

Production bug fix:
- AssumptionsList and AffectedDefinitionsList now accept | undefined and guard
  before calling .length (conversation API can omit these fields)
- Same defense applied in App.tsx via ?? [] fallbacks
@cjot
cjot force-pushed the feat/add-model-selection branch from 509a09e to 55b1e90 Compare July 28, 2026 20:06
@ktjn
ktjn merged commit 5b62cb2 into main Jul 29, 2026
17 of 18 checks passed
@ktjn
ktjn deleted the feat/add-model-selection branch July 29, 2026 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants