Files
llama.cpp/tools/ui/src/lib/components/app/models/ModelContext.svelte
T
Aleksander Grygier 2f524018e4 ui : group the model selector components
The selector surfaces move under models/ModelsSelector with their own
barrel: the dropdown and sheet relocate, the list, option and trigger icon
split out, and the shared list helpers join the navigation utils. The
searchable dropdown gains a sticky footer and per-surface class hooks.

Assisted-by: pi:llama.cpp/DeepSeek-V4.1-Flash
2026-09-30 15:31:11 +02:00

59 lines
1.7 KiB
Svelte

<script lang="ts">
import { isLocalOption } from './ModelsManager/utils';
import { HuggingFaceService } from '$lib/services';
import type { ModelOption } from '$lib/types/models';
import { nearViewport } from '$lib/utils';
import { formatParameters } from '$lib/utils/formatters';
interface Props {
class?: string;
/** Context the model is set to run with; paired with the supported one. */
configured?: number | null;
option: ModelOption;
}
let { class: className = '', configured = null, option }: Props = $props();
// a listing that reports a context window (OpenRouter, Groq, HF) needs no lookup
let reported = $derived(option.contextLength ?? null);
let isNearViewport = $state(false);
let fetched = $state<number | null>(null);
$effect(() => {
fetched = null;
if (reported || !isNearViewport || !isLocalOption(option)) return;
// a local GGUF carries its trained context in the model metadata
const repo = option.model.split(':')[0] ?? '';
if (!repo) return;
let cancelled = false;
void HuggingFaceService.getDetails(repo)
.then((details) => {
if (!cancelled) fetched = details?.gguf?.context_length ?? null;
})
// best-effort: offline or a repo we cannot read keeps the dash
.catch(() => {});
return () => {
cancelled = true;
};
});
let context = $derived(reported ?? fetched);
// `configured / supported`, or whichever of the two is known
let values = $derived(
[configured, context].filter((value): value is number => typeof value === 'number')
);
</script>
<span
use:nearViewport={() => (isNearViewport = true)}
class={['text-sm text-muted-foreground', className]}
>
{values.length ? `${values.map((value) => formatParameters(value)).join(' / ')} tokens` : '-'}
</span>