Spaces:
Sleeping
Sleeping
File size: 1,168 Bytes
06671aa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | from __future__ import annotations
import os
from fastapi import HTTPException
from inference.config import get_inference_manifest
# Legacy Python service env vars remain supported for credential fallback.
_LEGACY_API_KEY_ENVS = (
"TABULAR_AGENT_API_KEY",
"GOOGLE_API_KEY",
"GEMINI_API_KEY",
"WORD_REVIEW_API_KEY",
)
def resolve_api_key(provider: str = "google-genai") -> str | None:
manifest = get_inference_manifest()
providers = manifest.get("providers") or {}
provider_entry = providers.get(provider) or {}
api_key_env = provider_entry.get("apiKeyEnv")
if isinstance(api_key_env, str) and api_key_env.strip():
value = os.environ.get(api_key_env, "").strip()
if value:
return value
for env_name in _LEGACY_API_KEY_ENVS:
value = os.environ.get(env_name, "").strip()
if value:
return value
return None
def assert_api_key(provider: str = "proxy-openai") -> str:
key = resolve_api_key(provider)
if not key:
raise HTTPException(
status_code=500,
detail="TabularAgent API key is not configured.",
)
return key
|