mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-30 16:42:15 -04:00
Ignore invalid context budget numbers (#1831)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -33,6 +33,11 @@ def test_unknown_window_falls_back_to_configured():
|
||||
assert compute_input_token_budget(0, 0, explicit=False) == 6000 # default
|
||||
|
||||
|
||||
def test_invalid_numeric_inputs_fall_back_cleanly():
|
||||
assert compute_input_token_budget("bad", "also bad", explicit=False) == 6000
|
||||
assert compute_input_token_budget("bad", 128000, explicit=True) == int(128000 * 0.85)
|
||||
|
||||
|
||||
def test_is_setting_overridden_reads_raw_saved_file(tmp_path, monkeypatch):
|
||||
import src.settings as settings
|
||||
|
||||
|
||||
Reference in New Issue
Block a user