Skip to content

Commit a62be98

Browse files
add cashed icon to models in dropdown
1 parent 04921e5 commit a62be98

File tree

5 files changed

+78
-10
lines changed

5 files changed

+78
-10
lines changed

src/lib/components/ModelDropdown.svelte

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
currentModel,
44
availableModels,
55
isModelLoaded,
6-
modelLoadingProgress
6+
modelLoadingProgress,
7+
cachedModels,
8+
checkCachedModels
79
} from '$lib/stores/models';
810
import { loadModelWithChatBubble } from '$lib/utils/model-loading';
911
import { isMobile, getMobileOptimizedModels, canHandleLargeModels } from '$lib/utils/mobile';
@@ -109,10 +111,21 @@
109111
style="z-index: 999999 !important; top: {dropdownPosition.top}px; left: {dropdownPosition.left}px;"
110112
>
111113
<div class="p-4 border-b border-surface-300-600-token">
112-
<h3 class="font-semibold text-lg text-surface-700-200-token">Select LLM Model</h3>
113-
<p class="text-sm text-surface-700-200-token opacity-80">
114-
Choose from {$availableModels.length} available models
115-
</p>
114+
<div class="flex items-center justify-between">
115+
<div>
116+
<h3 class="font-semibold text-lg text-surface-700-200-token">Select LLM Model</h3>
117+
<p class="text-sm text-surface-700-200-token opacity-80">
118+
Choose from {$availableModels.length} available models
119+
</p>
120+
</div>
121+
<button
122+
class="btn btn-sm variant-ghost-surface"
123+
on:click={() => checkCachedModels()}
124+
title="Refresh cache status"
125+
>
126+
<i class="fa fa-refresh"></i>
127+
</button>
128+
</div>
116129
</div>
117130

118131
<!-- Fast/Lightweight Models -->
@@ -151,6 +164,11 @@
151164
<span class="text-xs text-yellow-400">{$modelLoadingProgress}%</span>
152165
{/if}
153166
</div>
167+
{:else if $cachedModels.has(model.model_id)}
168+
<div class="flex items-center space-x-1 flex-shrink-0">
169+
<i class="fa fa-download text-blue-400"></i>
170+
<span class="text-xs text-blue-400">Cached</span>
171+
</div>
154172
{/if}
155173
</div>
156174

@@ -218,6 +236,11 @@
218236
<span class="text-xs text-yellow-400">{$modelLoadingProgress}%</span>
219237
{/if}
220238
</div>
239+
{:else if $cachedModels.has(model.model_id)}
240+
<div class="flex items-center space-x-1 flex-shrink-0">
241+
<i class="fa fa-download text-blue-400"></i>
242+
<span class="text-xs text-blue-400">Cached</span>
243+
</div>
221244
{/if}
222245
</div>
223246

@@ -292,6 +315,11 @@
292315
<span class="text-xs text-warning-500">{$modelLoadingProgress}%</span>
293316
{/if}
294317
</div>
318+
{:else if $cachedModels.has(model.model_id)}
319+
<div class="flex items-center space-x-1 flex-shrink-0">
320+
<i class="fa fa-download text-blue-400"></i>
321+
<span class="text-xs text-blue-400">Cached</span>
322+
</div>
295323
{/if}
296324
</div>
297325

src/lib/components/ModelManager.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
availableModels,
55
downloadProgress,
66
currentModel,
7-
isModelLoaded
7+
isModelLoaded,
8+
cachedModels
89
} from '$lib/stores/models';
910
import { loadModelWithChatBubble } from '$lib/utils/model-loading';
1011
@@ -67,7 +68,10 @@
6768
<span class="badge variant-filled-success">Active</span>
6869
{:else if progress.downloading}
6970
<span class="badge variant-filled-warning">Downloading</span>
70-
{:else if progress.downloaded}
71+
{:else if progress.downloaded || $cachedModels.has(model.model_id)}
72+
<span class="badge variant-filled-tertiary">
73+
<i class="fa fa-download mr-1"></i> Cached
74+
</span>
7175
<button
7276
class="btn btn-sm variant-filled-primary"
7377
on:click={() => handleModelSwitch(model.model_id)}

src/lib/stores/models.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const currentModel = writable<string>('TinyLlama-1.1B-Chat-v0.4-q4f16_1-M
77
export const isModelLoaded = writable(false);
88
export const modelLoadingProgress = writable<number>(0);
99
export const modelLoadingStatus = writable<string>('');
10+
export const cachedModels = writable<Set<string>>(new Set());
1011

1112
export const MODELS: ModelInfo[] = [
1213
// Lightweight/Fast Models
@@ -171,3 +172,29 @@ export function setModelDownloaded(modelId: string) {
171172
}
172173
}));
173174
}
175+
176+
export async function checkCachedModels(): Promise<void> {
177+
console.log('🔍 Checking cached models...');
178+
const { webLLMService } = await import('../utils/webllm');
179+
const cached = new Set<string>();
180+
181+
for (const model of MODELS) {
182+
try {
183+
const isCached = await webLLMService.isModelAvailable(model.model_id);
184+
console.log(`Model ${model.model_id}: ${isCached ? 'CACHED' : 'not cached'}`);
185+
if (isCached) {
186+
cached.add(model.model_id);
187+
}
188+
} catch (error) {
189+
console.error(`Error checking cache for ${model.model_id}:`, error);
190+
}
191+
}
192+
193+
console.log(`✅ Found ${cached.size} cached models:`, Array.from(cached));
194+
cachedModels.set(cached);
195+
196+
// Also update downloadProgress for cached models
197+
cached.forEach(modelId => {
198+
setModelDownloaded(modelId);
199+
});
200+
}

src/lib/utils/webllm.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,11 @@ class WebLLMService {
421421
async isModelAvailable(modelId: string): Promise<boolean> {
422422
try {
423423
const webllm = await this.loadWebLLM();
424-
return await webllm.hasModelInCache(modelId);
425-
} catch {
424+
const result = await webllm.hasModelInCache(modelId);
425+
console.log(`Cache check for ${modelId}: ${result}`);
426+
return result;
427+
} catch (error) {
428+
console.error(`Error checking cache for ${modelId}:`, error);
426429
return false;
427430
}
428431
}

src/routes/+page.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@
99
import MobileLayout from '$lib/components/MobileLayout.svelte';
1010
import WelcomeGuide from '$lib/components/WelcomeGuide.svelte';
1111
import { isMobile } from '$lib/utils/mobile';
12+
import { checkCachedModels } from '$lib/stores/models';
1213
1314
let showDocumentManager = false;
1415
let showSidebar = false;
1516
let isMobileDevice = false;
1617
let showWelcomeGuide = false;
1718
18-
onMount(() => {
19+
onMount(async () => {
1920
isMobileDevice = isMobile();
21+
// Check which models are cached on startup with a small delay
22+
// to ensure WebLLM is ready
23+
setTimeout(() => {
24+
checkCachedModels().catch(console.error);
25+
}, 1000);
2026
});
2127
</script>
2228

0 commit comments

Comments
 (0)