DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(llm): name the Kimi k3 family once instead of per released id
Bingxi Zhao (Frank)26500eebfc76
diff --git a/deeptutor/services/provider_registry.py b/deeptutor/services/provider_registry.pyindex 5eda72682..da976a8fc 100644--- a/deeptutor/services/provider_registry.py+++ b/deeptutor/services/provider_registry.py@@ -44,8 +44,9 @@ class ProviderSpec:supports_prompt_caching: bool = Falsesupports_stream_options: bool = Truemodel_overrides: tuple[tuple[str, dict[str, Any]], ...] = ()- # Bare model ids too short or generic for substring-based vendor detection.- exact_model_ids: tuple[str, ...] = ()+ # Bare model-id families too short or generic for substring-based vendor+ # detection. See ``_matches_model_family`` for what a family covers.+ model_id_families: tuple[str, ...] = ()is_oauth: bool = Falseis_direct: bool = Falsethinking_style: str = ""@@ -421,13 +422,12 @@ PROVIDERS: tuple[ProviderSpec, ...] = (# not contain "kimi" and keeps the caller's temperature. The Kimi# coding endpoint (api.kimi.com/coding/v1) addresses these models by# bare ids ("k3", "k3-256k", ...) without the "kimi-" prefix, so- # match those too.+ # match the whole family too.model_overrides=(("kimi", {"temperature": None}),- ("=k3", {"temperature": None}),- ("=k3-256k", {"temperature": None}),+ ("^k3", {"temperature": None}),),- exact_model_ids=("k3", "k3-256k"),+ model_id_families=("k3",),),# MiniMax runs two separate platforms: global (platform.minimax.io /# api.minimax.io) and mainland China (platform.minimaxi.com /@@ -694,7 +694,7 @@ def find_by_model(model: str | None) -> ProviderSpec | None:if model_prefix and normalized_prefix == spec.name:return specfor spec in standard_specs:- if model_lower in spec.exact_model_ids:+ if any(_matches_model_family(family, model_lower) for family in spec.model_id_families):return specfor spec in standard_specs:if any(@@ -704,14 +704,30 @@ def find_by_model(model: str | None) -> ProviderSpec | None:return None+def _matches_model_family(family: str, model_lower: str) -> bool:+ """Whether *model_lower* is the bare id ``family`` or a variant of it.++ A vendor ships a family under one short id plus siblings distinguished by+ a dash suffix — ``k3`` alongside ``k3-256k``. Enumerating each sibling is+ how #1227 happened: ``k3`` had a rule, ``k3-256k`` shipped later, missed+ it, and got exactly the HTTP 400 the rule exists to prevent. Naming the+ family covers the siblings that do not exist yet, while a short id still+ cannot capture an unrelated one — ``sk3``, ``k30`` and ``k3x`` are all+ different models, and none of them is in this family.+ """+ return model_lower == family or model_lower.startswith(f"{family}-")++def _matching_overrides(spec: ProviderSpec, model_lower: str) -> dict[str, Any]:for pattern, overrides in spec.model_overrides:- # ``=name`` is an exact bare model id. Most historical patterns are- # vendor-family substrings, but a short id such as ``k3`` must not also- # match unrelated ids like ``sk3`` or ``k30``.- if (pattern.startswith("=") and model_lower == pattern[1:]) or (- not pattern.startswith("=") and pattern in model_lower- ):+ # ``^name`` is a bare model-id family; every other pattern is a+ # vendor-family substring.+ matched = (+ _matches_model_family(pattern[1:], model_lower)+ if pattern.startswith("^")+ else pattern in model_lower+ )+ if matched:return dict(overrides)return {}diff --git a/tests/services/llm/test_model_overrides.py b/tests/services/llm/test_model_overrides.pyindex ed0b1675f..553469697 100644--- a/tests/services/llm/test_model_overrides.py+++ b/tests/services/llm/test_model_overrides.py@@ -85,13 +85,22 @@ def test_vendor_prefixed_routing_still_finds_the_model() -> None:}-def test_bare_k3_is_exact_and_does_not_capture_unrelated_short_ids() -> None:+def test_the_k3_family_covers_its_variants_without_capturing_short_ids() -> None:+ """One family name, not one rule per released id.++ ``k3-256k`` was added to the Kimi coding endpoint after ``k3`` and got+ HTTP 400 on every call (#1227), because the rule named the one id that+ existed when it was written. A sibling that ships tomorrow is covered+ here; an unrelated short id still is not.+ """moonshot = find_by_name("moonshot")assert model_overrides_for("k3", moonshot) == {"temperature": None}assert model_overrides_for("k3-256k", moonshot) == {"temperature": None}+ assert model_overrides_for("k3-1m", moonshot) == {"temperature": None}assert model_overrides_for("sk3", moonshot) == {}assert model_overrides_for("k30", moonshot) == {}- assert model_overrides_for("k3-256kx", moonshot) == {}+ assert model_overrides_for("k3x", moonshot) == {}assert find_by_model("k3") is moonshotassert find_by_model("k3-256k") is moonshot+ assert find_by_model("k3-1m") is moonshotassert find_by_model("sk3") is None