30 lines
777 B
Python
30 lines
777 B
Python
"""Adaptive RAG shared utils."""
|
|
from __future__ import annotations
|
|
|
|
from .shared_imports import *
|
|
|
|
def _env_bool(name: str, default: bool = False) -> bool:
|
|
raw = str(os.getenv(name, "") or "").strip().lower()
|
|
if not raw:
|
|
return bool(default)
|
|
if raw in {"1", "true", "yes", "on"}:
|
|
return True
|
|
if raw in {"0", "false", "no", "off"}:
|
|
return False
|
|
return bool(default)
|
|
|
|
|
|
def _env_int(name: str, default: int, *, minimum: int, maximum: int) -> int:
|
|
raw = str(os.getenv(name, "") or "").strip()
|
|
if not raw:
|
|
value = int(default)
|
|
else:
|
|
try:
|
|
value = int(raw)
|
|
except Exception:
|
|
value = int(default)
|
|
return max(minimum, min(maximum, value))
|
|
|
|
|
|
__all__ = ["_env_bool", "_env_int"]
|