Files
magpie/internal/catalog/name_window_test.go
T
yetone 9192b78323 provider: a model's name that says its window is the window when nothing else does (maohy915 on X)
v0.1.3905 read an Ollama model's num_ctx from the Modelfile; maohy915 meant
the name itself ("Qwen-3.8-27b-128k"), which needs no Modelfile.

catalog.NameWindow reads the last part of an id (or of an Ollama tag,
"qwen:27b-128k", "qwen3-128k:latest") when it is a number and a unit alone:
4 to 2048 k, or 1, 2, 4, 5, 8, 10 m, as 1,000 and 1,000,000 like a "[200k]"
mark. Not read as a window: a size (27b, pythia-14m, smollm-135m), a date
(gpt-4o-2024), a quant (q4_k_m), a lone "128k", 1k, 3m, 1.5m, a size
followed by more words.

It is the last word: ListedWindow reads the list's window, then models.dev's,
then the name; a window the user typed (per model or "*") still wins in
windowIn. For a local Ollama list the name replaces the architecture's
maximum (the fallback) but never a num_ctx the Modelfile sets.

Run (mote-run): go test ./internal/catalog ./internal/provider with
NameWindow's edge table, the user/list/catalog order, and an Ollama list
with a fake /api/show; TestNameWindowIsTheLastWord red with the
ListedWindow line returned as 0. Not tried: a real Ollama server; the name's
window is not sent to Ollama as num_ctx.
2026-11-12 22:27:39 +08:00

50 lines
1.6 KiB
Go

package catalog
import "testing"
// maohy915 on X: a model's name that says its window ("Qwen-3.8-27b-128k")
// is the window when nothing else says one. Only a last part of the id that
// is a context size alone counts; a model's size, version, date or quant
// is not read as one.
func TestNameWindow(t *testing.T) {
for id, want := range map[string]int{
"Qwen-3.8-27b-128k": 128_000,
"qwen-3.8-27b-128K": 128_000,
"llama3-8b-32k": 32_000,
"gpt-4-32k": 32_000,
"my_model_200k": 200_000,
"model-1m": 1_000_000,
"llama-4-scout-10m": 10_000_000,
"qwen3 256k": 256_000,
"local/qwen3-27b-128k": 128_000,
"qwen:27b-128k": 128_000,
"qwen3-128k:latest": 128_000,
"qwen3-128k:8b": 128_000,
"gpt-4o-2024": 0,
"gpt-4o-2024-08-06": 0,
"qwen-3.8-27b": 0,
"pythia-14m": 0,
"smollm-135m": 0,
"gpt2-124m": 0,
"llama3-q4_k_m": 0,
"llama3:8b-instruct-q4_0": 0,
"128k": 0,
"-128k": 0,
"model-128k-instruct": 0,
"model-0k": 0,
"model-1k": 0,
"model-4096k": 0,
"model-3m": 0,
"model-012k": 0,
"model-1.5m": 0,
"model-k": 0,
"model-": 0,
"qwen3:8b-instruct": 0,
"": 0,
} {
if got := NameWindow(id); got != want {
t.Errorf("%q: %d, want %d", id, got, want)
}
}
}