fix(config): Ensure API keys are loaded by orchestrator
- Reverts docker-compose.yml to use volume mount for gemini_api_key.txt, due to format constraints. - Restores and refines Config.load_api_keys() in config.py. - **Crucially, calls Config.load_api_keys() at the start of gtm_architect_orchestrator.py to ensure keys are loaded.** - Adjusts _get_gemini_api_key in helpers.py to prioritize keys from Config.API_KEYS. - This definitively addresses the 'API Key missing' error by guaranteeing key initialization.
This commit is contained in:
25
helpers.py
25
helpers.py
@@ -294,31 +294,30 @@ def get_email_address(firstname, lastname, website):
|
||||
|
||||
def _get_gemini_api_key():
|
||||
"""
|
||||
Retrieves Gemini API Key, prioritizing environment variables as the most robust method.
|
||||
Retrieves Gemini API Key, prioritizing Config.API_KEYS after it has been loaded.
|
||||
"""
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.info("Attempting to retrieve Gemini API Key...")
|
||||
|
||||
# Primary Method: Environment Variable (most robust for Docker)
|
||||
# Primary Method: From Config.API_KEYS (expected to be loaded by orchestrator)
|
||||
api_key = Config.API_KEYS.get('gemini') or Config.API_KEYS.get('openai') # Check both slots
|
||||
if api_key:
|
||||
logging.info("Successfully loaded API key from Config.API_KEYS.")
|
||||
return api_key
|
||||
|
||||
# Fallback 1: Environment Variable GEMINI_API_KEY
|
||||
api_key = os.environ.get("GEMINI_API_KEY")
|
||||
if api_key:
|
||||
logging.info("Successfully loaded API key from GEMINI_API_KEY environment variable.")
|
||||
logging.warning("Loaded API key from GEMINI_API_KEY environment variable (Config.API_KEYS was empty).")
|
||||
return api_key
|
||||
|
||||
# Fallback 1: Legacy Environment Variable
|
||||
# Fallback 2: Legacy Environment Variable OPENAI_API_KEY
|
||||
api_key = os.environ.get("OPENAI_API_KEY")
|
||||
if api_key:
|
||||
logging.warning("Loaded API key from legacy OPENAI_API_KEY environment variable.")
|
||||
return api_key
|
||||
|
||||
# Fallback 2: File-based (less reliable with volume mounts)
|
||||
logging.warning("Could not find API key in environment variables. Falling back to file-based method.")
|
||||
api_key = Config.API_KEYS.get('openai') # Legacy slot in config
|
||||
if api_key:
|
||||
logging.info("Successfully loaded API key from config file.")
|
||||
logging.warning("Loaded API key from legacy OPENAI_API_KEY environment variable (Config.API_KEYS was empty).")
|
||||
return api_key
|
||||
|
||||
logger.error("CRITICAL: No API Key found in environment variables or config file.")
|
||||
logger.error("CRITICAL: No API Key found in Config.API_KEYS or environment variables.")
|
||||
raise ValueError("API Key missing.")
|
||||
|
||||
@retry_on_failure
|
||||
|
||||
Reference in New Issue
Block a user