Skip to content

Commit e532eb6

Browse files
authored
Merge pull request NousResearch#1724 from NousResearch/fix/model-metadata-fuzzy-match
fix(metadata): fuzzy context length match can return wrong model's value
2 parents 21c952e + 6e3817b commit e532eb6

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

agent/model_metadata.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,10 @@ def get_model_context_length(model: str, base_url: str = "") -> int:
266266
if model in metadata:
267267
return metadata[model].get("context_length", 128000)
268268

269-
# 3. Hardcoded defaults (fuzzy match)
270-
for default_model, length in DEFAULT_CONTEXT_LENGTHS.items():
269+
# 3. Hardcoded defaults (fuzzy match — longest key first for specificity)
270+
for default_model, length in sorted(
271+
DEFAULT_CONTEXT_LENGTHS.items(), key=lambda x: len(x[0]), reverse=True
272+
):
271273
if default_model in model or model in default_model:
272274
return length
273275

0 commit comments

Comments
 (0)