Fix backend detection when environment variables contain only whitespace
This commit is contained in:
parent
c42a18e9e5
commit
e8188a56c7
1 changed files with 10 additions and 5 deletions
|
|
@ -57,6 +57,10 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# ─── Backend Selection ────────────────────────────────────────────────────────
|
# ─── Backend Selection ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
def _has_env(name: str) -> bool:
|
||||||
|
val = os.getenv(name)
|
||||||
|
return bool(val and val.strip())
|
||||||
|
|
||||||
def _load_web_config() -> dict:
|
def _load_web_config() -> dict:
|
||||||
"""Load the ``web:`` section from ~/.hermes/config.yaml."""
|
"""Load the ``web:`` section from ~/.hermes/config.yaml."""
|
||||||
try:
|
try:
|
||||||
|
|
@ -65,7 +69,6 @@ def _load_web_config() -> dict:
|
||||||
except (ImportError, Exception):
|
except (ImportError, Exception):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
def _get_backend() -> str:
|
def _get_backend() -> str:
|
||||||
"""Determine which web backend to use.
|
"""Determine which web backend to use.
|
||||||
|
|
||||||
|
|
@ -76,18 +79,20 @@ def _get_backend() -> str:
|
||||||
configured = _load_web_config().get("backend", "").lower().strip()
|
configured = _load_web_config().get("backend", "").lower().strip()
|
||||||
if configured in ("parallel", "firecrawl", "tavily"):
|
if configured in ("parallel", "firecrawl", "tavily"):
|
||||||
return configured
|
return configured
|
||||||
|
|
||||||
# Fallback for manual / legacy config — use whichever key is present.
|
# Fallback for manual / legacy config — use whichever key is present.
|
||||||
has_firecrawl = bool(os.getenv("FIRECRAWL_API_KEY") or os.getenv("FIRECRAWL_API_URL"))
|
has_firecrawl = _has_env("FIRECRAWL_API_KEY") or _has_env("FIRECRAWL_API_URL")
|
||||||
has_parallel = bool(os.getenv("PARALLEL_API_KEY"))
|
has_parallel = _has_env("PARALLEL_API_KEY")
|
||||||
has_tavily = bool(os.getenv("TAVILY_API_KEY"))
|
has_tavily = _has_env("TAVILY_API_KEY")
|
||||||
|
|
||||||
if has_tavily and not has_firecrawl and not has_parallel:
|
if has_tavily and not has_firecrawl and not has_parallel:
|
||||||
return "tavily"
|
return "tavily"
|
||||||
if has_parallel and not has_firecrawl:
|
if has_parallel and not has_firecrawl:
|
||||||
return "parallel"
|
return "parallel"
|
||||||
|
|
||||||
# Default to firecrawl (backward compat, or when both are set)
|
# Default to firecrawl (backward compat, or when both are set)
|
||||||
return "firecrawl"
|
return "firecrawl"
|
||||||
|
|
||||||
|
|
||||||
# ─── Firecrawl Client ────────────────────────────────────────────────────────
|
# ─── Firecrawl Client ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
_firecrawl_client = None
|
_firecrawl_client = None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue