mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-21 10:22:18 +00:00
fix(utils): add env_float helper for safe float env var parsing
Mirrors the existing env_int() helper: returns the default when the variable is unset or non-numeric instead of raising ValueError. Used by the follow-up commit to guard malformed float env vars across the gateway. Salvaged from #48735 (@annguyenNous). The PR's api_server.py change is now redundant — main guards HERMES_MAX_ITERATIONS via _current_max_iterations().
This commit is contained in:
parent
15852722d4
commit
06ca1e9980
1 changed files with 11 additions and 0 deletions
11
utils.py
11
utils.py
|
|
@ -323,6 +323,17 @@ def env_int(key: str, default: int = 0) -> int:
|
|||
return default
|
||||
|
||||
|
||||
def env_float(key: str, default: float = 0.0) -> float:
|
||||
"""Read an environment variable as a float, with fallback."""
|
||||
raw = os.getenv(key, "").strip()
|
||||
if not raw:
|
||||
return default
|
||||
try:
|
||||
return float(raw)
|
||||
except (ValueError, TypeError):
|
||||
return default
|
||||
|
||||
|
||||
def env_bool(key: str, default: bool = False) -> bool:
|
||||
"""Read an environment variable as a boolean."""
|
||||
return is_truthy_value(os.getenv(key, ""), default=default)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue