Ignore invalid context budget numbers (#1831)

This commit is contained in:
red person
2026-06-29 11:56:17 -07:00
committed by GitHub
parent bbbe145247
commit df9c20e6c2
2 changed files with 14 additions and 2 deletions
+9 -2
View File
@@ -18,6 +18,13 @@ DEFAULT_BUDGET = 6000
DEFAULT_HEADROOM = 0.85
def _int_or_zero(value) -> int:
try:
return int(value or 0)
except (TypeError, ValueError):
return 0
def compute_input_token_budget(
configured: int,
context_length: int,
@@ -48,8 +55,8 @@ def compute_input_token_budget(
- When the window is unknown (context_length <= 0), use the conservative
``default`` budget and do NOT scale off the fallback.
"""
configured = int(configured or 0)
context_length = int(context_length or 0)
configured = _int_or_zero(configured)
context_length = _int_or_zero(context_length)
if explicit and configured > 0:
return min(configured, context_length) if context_length > 0 else configured