Merge pull request #1724 from NousResearch/fix/model-metadata-fuzzy-match

fix(metadata): fuzzy context length match can return wrong model's value
This commit is contained in:
Teknium 2026-03-17 04:13:56 -07:00 committed by GitHub
commit 0878e5f4a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -266,8 +266,10 @@ def get_model_context_length(model: str, base_url: str = "") -> int:
if model in metadata:
return metadata[model].get("context_length", 128000)
# 3. Hardcoded defaults (fuzzy match)
for default_model, length in DEFAULT_CONTEXT_LENGTHS.items():
# 3. Hardcoded defaults (fuzzy match — longest key first for specificity)
for default_model, length in sorted(
DEFAULT_CONTEXT_LENGTHS.items(), key=lambda x: len(x[0]), reverse=True
):
if default_model in model or model in default_model:
return length