Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(chat): surface load stage on multi-stage loads, drop the load bar
Akarshan Biswas81555ebbf173
diff --git a/src-tauri/plugins/tauri-plugin-llamacpp/src/commands.rs b/src-tauri/plugins/tauri-plugin-llamacpp/src/commands.rsindex f6dc4457f..b1ae0d7da 100644--- a/src-tauri/plugins/tauri-plugin-llamacpp/src/commands.rs+++ b/src-tauri/plugins/tauri-plugin-llamacpp/src/commands.rs@@ -41,10 +41,18 @@ async fn http_client() -> reqwest::Client {/// Payload for the `llamacpp-model-load-progress` event, mirrored from the/// router's `/models/sse` `status_change` events (`progress.value` is 0.0-1.0).+/// `stage` is the upstream stage identifier being loaded right now+/// (`text_model` | `mmproj_model` | `spec_model`); `stages` is the full set+/// for this load - always includes `text_model`, plus `mmproj_model` for a+/// vision-capable model and/or `spec_model` for speculative decoding. A+/// plain text-only load (the common case) has exactly one stage, so the+/// frontend uses `stages.len() > 1` to decide whether naming the stage is+/// worth surfacing at all.#[derive(serde::Serialize, Clone)]pub struct LoadProgressPayload {pub model: String,pub stage: Option<String>,+ pub stages: Vec<String>,pub value: f64,}@@ -74,9 +82,19 @@ fn parse_load_progress_event(block: &str, model_id: &str) -> Option<LoadProgress.get("current").and_then(|v| v.as_str()).map(|s| s.to_string());+ let stages = progress+ .get("stages")+ .and_then(|v| v.as_array())+ .map(|arr| {+ arr.iter()+ .filter_map(|s| s.as_str().map(|s| s.to_string()))+ .collect()+ })+ .unwrap_or_default();return Some(LoadProgressPayload {model: model_id.to_string(),stage,+ stages,value,});}@@ -954,9 +972,43 @@ mod load_progress_tests {let payload = parse_load_progress_event(&block, "model-1").expect("should parse");assert_eq!(payload.model, "model-1");assert_eq!(payload.stage.as_deref(), Some("text_model"));+ assert_eq!(payload.stages, vec!["text_model".to_string()]);assert!((payload.value - 0.42).abs() < f64::EPSILON);}+ #[test]+ fn parses_a_multi_stage_vision_model_load() {+ let block = sse_block(+ "model-1",+ "status_change",+ serde_json::json!({+ "status": "loading",+ "progress": {+ "stages": ["text_model", "mmproj_model"],+ "current": "mmproj_model",+ "value": 0.8+ }+ }),+ );+ let payload = parse_load_progress_event(&block, "model-1").expect("should parse");+ assert_eq!(payload.stage.as_deref(), Some("mmproj_model"));+ assert_eq!(+ payload.stages,+ vec!["text_model".to_string(), "mmproj_model".to_string()]+ );+ }++ #[test]+ fn defaults_missing_stages_array_to_empty() {+ let block = sse_block(+ "model-1",+ "status_change",+ serde_json::json!({ "progress": { "current": "text_model", "value": 0.5 } }),+ );+ let payload = parse_load_progress_event(&block, "model-1").expect("should parse");+ assert!(payload.stages.is_empty());+ }+#[test]fn ignores_events_for_a_different_model() {let block = sse_block(diff --git a/web-app/src/components/PromptProgress.tsx b/web-app/src/components/PromptProgress.tsxindex 295325a1c..b318808b4 100644--- a/web-app/src/components/PromptProgress.tsx+++ b/web-app/src/components/PromptProgress.tsx@@ -39,9 +39,18 @@ export function PromptProgress({ hideIdle = false }: { hideIdle?: boolean }) {const loadPercentage =loadingModel && loadProgress ? Math.round(loadProgress.value * 100) : undefined+ // Only worth naming the stage when the load actually has more than one+ // (vision encoder and/or speculative-decoding draft model on top of the+ // main weights) - a plain text-only load is always a single "text_model"+ // stage for its entire duration, so calling that out would be noise.+ const stageLabel =+ loadingModel && loadProgress && (loadProgress.stages?.length ?? 0) > 1+ ? describeLoadStage(loadProgress.stage)+ : undefined+const label = loadingModel? loadPercentage !== undefined- ? `Loading model: ${loadPercentage}%`+ ? `Loading ${stageLabel ?? 'model'}: ${loadPercentage}%`: 'Loading model…': showReading? `Reading: ${percentage}%`@@ -59,9 +68,6 @@ export function PromptProgress({ hideIdle = false }: { hideIdle?: boolean }) {{showReading && !loadingModel && (<Progress value={percentage} className="h-1 bg-secondary/60" />)}- {loadingModel && loadPercentage !== undefined && (- <Progress value={loadPercentage} className="h-1 bg-secondary/60" />- )}{detail && (<div className="text-xs text-muted-foreground tabular-nums">{detail}@@ -71,6 +77,19 @@ export function PromptProgress({ hideIdle = false }: { hideIdle?: boolean }) {)}+function describeLoadStage(stage: string | undefined): string | undefined {+ switch (stage) {+ case 'text_model':+ return 'text model'+ case 'mmproj_model':+ return 'vision encoder'+ case 'spec_model':+ return 'draft model'+ default:+ return undefined+ }+}+function buildDetail(progress: {processed: numbertotal: numberdiff --git a/web-app/src/components/__tests__/PromptProgress.test.tsx b/web-app/src/components/__tests__/PromptProgress.test.tsxindex 0e9e8c0e4..1924f07d9 100644--- a/web-app/src/components/__tests__/PromptProgress.test.tsx+++ b/web-app/src/components/__tests__/PromptProgress.test.tsx@@ -71,6 +71,70 @@ describe('PromptProgress', () => {expect(screen.getByText('Loading model: 42%')).toBeInTheDocument()})+ it('should not render a progress bar while loading a model', () => {+ mockUseAppState.mockImplementation((selector) =>+ selector({+ promptProgress: undefined,+ loadingModel: true,+ modelLoadProgress: { modelId: 'model-1', value: 0.42 },+ })+ )++ const { container } = render(<PromptProgress />)++ expect(screen.getByText('Loading model: 42%')).toBeInTheDocument()+ expect(container.querySelector('[data-slot="progress"]')).toBeNull()+ })++ it('should still render the progress bar while reading (unaffected by the load-bar removal)', () => {+ const mockProgress = { cache: 0, processed: 50, time_ms: 500, total: 100 }+ mockUseAppState.mockImplementation((selector) =>+ selector({ promptProgress: mockProgress, loadingModel: false })+ )++ const { container } = render(<PromptProgress />)++ expect(container.querySelector('[data-slot="progress"]')).not.toBeNull()+ })++ it('should name the stage when a load has more than one (vision model)', () => {+ mockUseAppState.mockImplementation((selector) =>+ selector({+ promptProgress: undefined,+ loadingModel: true,+ modelLoadProgress: {+ modelId: 'model-1',+ value: 0.8,+ stage: 'mmproj_model',+ stages: ['text_model', 'mmproj_model'],+ },+ })+ )++ render(<PromptProgress />)++ expect(screen.getByText('Loading vision encoder: 80%')).toBeInTheDocument()+ })++ it('should not name the stage for a plain single-stage text-only load', () => {+ mockUseAppState.mockImplementation((selector) =>+ selector({+ promptProgress: undefined,+ loadingModel: true,+ modelLoadProgress: {+ modelId: 'model-1',+ value: 0.5,+ stage: 'text_model',+ stages: ['text_model'],+ },+ })+ )++ render(<PromptProgress />)++ expect(screen.getByText('Loading model: 50%')).toBeInTheDocument()+ })+it('should fall back to generic loading label when no progress event has arrived yet', () => {mockUseAppState.mockImplementation((selector) =>selector({diff --git a/web-app/src/containers/dialogs/LlamacppOomListener.tsx b/web-app/src/containers/dialogs/LlamacppOomListener.tsxindex d1f73d606..7ccc2ad13 100644--- a/web-app/src/containers/dialogs/LlamacppOomListener.tsx+++ b/web-app/src/containers/dialogs/LlamacppOomListener.tsx@@ -12,6 +12,7 @@ import {type LoadProgressPayload = {model: stringstage?: string+ stages: string[]value: number}@@ -49,8 +50,8 @@ export default function LlamacppOomListener() {const unlistenLoadProgress = listen<LoadProgressPayload>('llamacpp-model-load-progress',(event) => {- const { model, stage, value } = event.payload- const progress = { modelId: model, stage, value }+ const { model, stage, stages, value } = event.payload+ const progress = { modelId: model, stage, stages, value }useAppState.getState().updateModelLoadProgress(progress)const threadId = useAppState.getState().currentStreamThreadIdif (threadId) {diff --git a/web-app/src/containers/dialogs/__tests__/LlamacppOomListener.test.tsx b/web-app/src/containers/dialogs/__tests__/LlamacppOomListener.test.tsxindex 69600588e..2847298b0 100644--- a/web-app/src/containers/dialogs/__tests__/LlamacppOomListener.test.tsx+++ b/web-app/src/containers/dialogs/__tests__/LlamacppOomListener.test.tsx@@ -44,13 +44,19 @@ describe('LlamacppOomListener - model load progress', () => {expect(loadProgressHandler).toBeDefined()act(() => {loadProgressHandler?.({- payload: { model: 'model-1', stage: 'text_model', value: 0.75 },+ payload: {+ model: 'model-1',+ stage: 'mmproj_model',+ stages: ['text_model', 'mmproj_model'],+ value: 0.75,+ },})})expect(useAppState.getState().modelLoadProgress).toEqual({modelId: 'model-1',- stage: 'text_model',+ stage: 'mmproj_model',+ stages: ['text_model', 'mmproj_model'],value: 0.75,})})diff --git a/web-app/src/hooks/useAppState.ts b/web-app/src/hooks/useAppState.tsindex 86b722efc..89341fab3 100644--- a/web-app/src/hooks/useAppState.ts+++ b/web-app/src/hooks/useAppState.ts@@ -20,6 +20,7 @@ export type ModelLoadProgress = {modelId: stringvalue: numberstage?: string+ stages?: string[]}type AppErrorMessage = {