Merge branch 'type_error_cai_max_turns' into '0.4.0'

Fix CAI_MAX_TURNS type error

See merge request aliasrobotics/alias_research/cai!168
This commit is contained in:
Luis Javier Navarrete Lozano 2025-05-13 11:27:50 +00:00
commit 2f90004623
1 changed files with 12 additions and 1 deletions

View File

@ -45,7 +45,18 @@ from .usage import Usage
from .util import _coro, _error_tracing
import os
DEFAULT_MAX_TURNS = os.getenv("CAI_MAX_TURNS", float("inf"))
# CAI_MAX_TURNS must be converted to an int to avoid type mismatch error when comparing.
max_turns_env = os.getenv("CAI_MAX_TURNS")
if max_turns_env is not None:
try:
DEFAULT_MAX_TURNS = int(max_turns_env)
except ValueError:
try:
DEFAULT_MAX_TURNS = float(max_turns_env)
except ValueError:
DEFAULT_MAX_TURNS = float("inf")
else:
DEFAULT_MAX_TURNS = float("inf")
@dataclass