fix: Context info fixes & improvements

This commit is contained in:
Aleksander Grygier 2026-02-06 14:54:26 +01:00
parent 2d8d094eaf
commit 9ea59333b8
9 changed files with 50 additions and 21 deletions

View File

@ -59,7 +59,12 @@
<span class="font-medium">Prompt tokens:</span>
{contextInfo.n_prompt_tokens.toLocaleString()}
</p>
<p><span class="font-medium">Context size:</span> {contextInfo.n_ctx.toLocaleString()}</p>
{#if contextInfo.n_ctx}
<p>
<span class="font-medium">Context size:</span>
{contextInfo.n_ctx.toLocaleString()}
</p>
{/if}
</div>
{/if}
</div>

View File

@ -105,12 +105,21 @@
</Table.Row>
<!-- Context Size -->
<Table.Row>
<Table.Cell class="h-10 align-middle font-medium">Context Size</Table.Cell>
<Table.Cell
>{formatNumber(serverProps.default_generation_settings.n_ctx)} tokens</Table.Cell
>
</Table.Row>
{#if serverProps?.default_generation_settings?.n_ctx}
<Table.Row>
<Table.Cell class="h-10 align-middle font-medium">Context Size</Table.Cell>
<Table.Cell
>{formatNumber(serverProps.default_generation_settings.n_ctx)} tokens</Table.Cell
>
</Table.Row>
{:else}
<Table.Row>
<Table.Cell class="h-10 align-middle font-medium text-red-500"
>Context Size</Table.Cell
>
<Table.Cell class="text-red-500">Not available</Table.Cell>
</Table.Row>
{/if}
<!-- Training Context -->
{#if modelMeta?.n_ctx_train}

View File

@ -48,7 +48,7 @@
{model || 'Unknown Model'}
</Badge>
{#if serverData.default_generation_settings.n_ctx}
{#if serverData?.default_generation_settings?.n_ctx}
<Badge variant="secondary" class="text-xs">
ctx: {serverData.default_generation_settings.n_ctx.toLocaleString()}
</Badge>

View File

@ -1 +0,0 @@
export const DEFAULT_CONTEXT = 4096;

View File

@ -147,7 +147,11 @@ export function useProcessingState(): UseProcessingStateReturn {
}
// Always show context info when we have valid data
if (stateToUse.contextUsed >= 0 && stateToUse.contextTotal > 0) {
if (
typeof stateToUse.contextTotal === 'number' &&
stateToUse.contextUsed >= 0 &&
stateToUse.contextTotal > 0
) {
const contextPercent = Math.round((stateToUse.contextUsed / stateToUse.contextTotal) * 100);
details.push(
@ -193,7 +197,11 @@ export function useProcessingState(): UseProcessingStateReturn {
const details: string[] = [];
// Always show context info when we have valid data
if (stateToUse.contextUsed >= 0 && stateToUse.contextTotal > 0) {
if (
typeof stateToUse.contextTotal === 'number' &&
stateToUse.contextUsed >= 0 &&
stateToUse.contextTotal > 0
) {
const contextPercent = Math.round((stateToUse.contextUsed / stateToUse.contextTotal) * 100);
details.push(

View File

@ -30,7 +30,6 @@ import {
findLeafNode,
isAbortError
} from '$lib/utils';
import { DEFAULT_CONTEXT } from '$lib/constants/default-context';
import { SYSTEM_MESSAGE_PLACEHOLDER } from '$lib/constants/ui';
import { REASONING_TAGS } from '$lib/constants/agentic';
import {
@ -1252,17 +1251,22 @@ class ChatStore {
}
}
private getContextTotal(): number {
private getContextTotal(): number | null {
const activeConvId = this.activeConversationId;
const activeState = activeConvId ? this.getProcessingState(activeConvId) : null;
if (activeState && activeState.contextTotal > 0) return activeState.contextTotal;
if (activeState && typeof activeState.contextTotal === 'number' && activeState.contextTotal > 0)
return activeState.contextTotal;
if (isRouterMode()) {
const modelContextSize = selectedModelContextSize();
if (modelContextSize && modelContextSize > 0) return modelContextSize;
if (typeof modelContextSize === 'number' && modelContextSize > 0) return modelContextSize;
} else {
const propsContextSize = contextSize();
if (typeof propsContextSize === 'number' && propsContextSize > 0) return propsContextSize;
}
const propsContextSize = contextSize();
if (propsContextSize && propsContextSize > 0) return propsContextSize;
return DEFAULT_CONTEXT;
return null;
}
updateProcessingStateFromTimings(

View File

@ -178,7 +178,9 @@ class ModelsStore {
*/
getModelContextSize(modelId: string): number | null {
const props = this.getModelProps(modelId);
return props?.default_generation_settings?.n_ctx ?? null;
const nCtx = props?.default_generation_settings?.n_ctx;
return typeof nCtx === 'number' ? nCtx : null;
}
/**

View File

@ -45,7 +45,9 @@ class ServerStore {
}
get contextSize(): number | null {
return this.props?.default_generation_settings?.n_ctx ?? null;
const nCtx = this.props?.default_generation_settings?.n_ctx;
return typeof nCtx === 'number' ? nCtx : null;
}
get webuiSettings(): Record<string, string | number | boolean> | undefined {

View File

@ -351,7 +351,7 @@ export interface ApiProcessingState {
tokensDecoded: number;
tokensRemaining: number;
contextUsed: number;
contextTotal: number;
contextTotal: number | null;
outputTokensUsed: number; // Total output tokens (thinking + regular content)
outputTokensMax: number; // Max output tokens allowed
temperature: number;