import os import configparser import logging from dotenv import load_dotenv # Local .env file load_dotenv() def getconfig(configfile_path: str): """ Read the config file Params ---------------- configfile_path: file path of .cfg file """ config = configparser.ConfigParser() try: config.read_file(open(configfile_path)) return config except: logging.warning("config file not found") # --------------------------------------------------------------------- # Provider-agnostic authentication and configuration # --------------------------------------------------------------------- def get_auth(provider: str) -> dict: """Get authentication configuration for different providers""" auth_configs = { "openai": {"api_key": os.getenv("OPENAI_API_KEY")}, "huggingface": {"api_key": os.getenv("HF_TOKEN")}, "anthropic": {"api_key": os.getenv("ANTHROPIC_API_KEY")}, "cohere": {"api_key": os.getenv("COHERE_API_KEY")}, } if provider not in auth_configs: raise ValueError(f"Unsupported provider: {provider}") auth_config = auth_configs[provider] api_key = auth_config.get("api_key") if not api_key: raise RuntimeError(f"Missing API key for provider '{provider}'. Please set the appropriate environment variable.") return auth_config