diff --git a/frontend/src/lib/components/chat/ChatWindow.svelte b/frontend/src/lib/components/chat/ChatWindow.svelte index acaf7d4..d95bdb6 100644 --- a/frontend/src/lib/components/chat/ChatWindow.svelte +++ b/frontend/src/lib/components/chat/ChatWindow.svelte @@ -182,6 +182,15 @@ } }); + // Sync custom context limit with settings + $effect(() => { + if (settingsState.useCustomParameters) { + contextManager.setCustomContextLimit(settingsState.num_ctx); + } else { + contextManager.setCustomContextLimit(null); + } + }); + // Update context manager when messages change $effect(() => { contextManager.updateMessages(chatState.visibleMessages); diff --git a/frontend/src/lib/memory/context-manager.svelte.ts b/frontend/src/lib/memory/context-manager.svelte.ts index 85821aa..2b0e5da 100644 --- a/frontend/src/lib/memory/context-manager.svelte.ts +++ b/frontend/src/lib/memory/context-manager.svelte.ts @@ -24,8 +24,14 @@ class ContextManager { /** Current model name */ currentModel = $state(''); - /** Maximum context length for current model */ - maxTokens = $state(4096); + /** Maximum context length for current model (from model lookup) */ + modelMaxTokens = $state(4096); + + /** Custom context limit override (from user settings) */ + customMaxTokens = $state(null); + + /** Effective max tokens (custom override or model default) */ + maxTokens = $derived(this.customMaxTokens ?? this.modelMaxTokens); /** * Cached token estimates for messages (id -> estimate) @@ -94,7 +100,15 @@ class ContextManager { */ setModel(modelName: string): void { this.currentModel = modelName; - this.maxTokens = getModelContextLimit(modelName); + this.modelMaxTokens = getModelContextLimit(modelName); + } + + /** + * Set custom context limit override + * Pass null to clear and use model default + */ + setCustomContextLimit(tokens: number | null): void { + this.customMaxTokens = tokens; } /**