Agentic-Codenames-Arena / support /api_keys_manager.py
lucadipalma
adding files
aa2d45f
TEAM_API_KEY_MAP = {
"openai": ("OPENAI_API_KEY", "OpenAI API Key"),
"google": ("GOOGLE_API_KEY", "Google API Key"),
"anthropic": ("ANTHROPIC_API_KEY", "Anthropic API Key"),
"opensource": ("HUGGINGFACEHUB_API_TOKEN", "HuggingFace API Token"),
}
def get_required_teams(red_team, blue_team):
"""Get unique teams that require API keys."""
teams = set()
# Handle random selections - could be any team
if red_team == "random":
teams.update(["openai", "google", "anthropic", "opensource"])
else:
teams.add(red_team)
if blue_team == "random":
teams.update(["openai", "google", "anthropic", "opensource"])
else:
teams.add(blue_team)
return sorted(teams)
def validate_api_keys(red_team, blue_team, openai_key, google_key, anthropic_key, hf_key, current_api_keys):
"""Validate that all required API keys are provided."""
required_teams = get_required_teams(red_team, blue_team)
# Build the API keys dictionary
api_keys = {}
missing_keys = []
key_mapping = {
"openai": (openai_key, "OPENAI_API_KEY", "OpenAI"),
"google": (google_key, "GOOGLE_API_KEY", "Google"),
"anthropic": (anthropic_key, "ANTHROPIC_API_KEY", "Anthropic"),
"opensource": (hf_key, "HUGGINGFACEHUB_API_TOKEN", "HuggingFace")
}
for team in required_teams:
key_value, key_name, display_name = key_mapping[team]
if key_value and key_value.strip():
api_keys[key_name] = key_value.strip()
else:
missing_keys.append(display_name)
if missing_keys:
error_msg = f"⚠️ Missing API keys for: {', '.join(missing_keys)}"
return api_keys, False, error_msg
return api_keys, True, "✅ All API keys validated!"