use new env validation module
This commit is contained in:
parent
674e08c89e
commit
64a64053b8
|
|
@ -298,95 +298,6 @@ def run_research_subtasks(base_task: str, config: dict, model, expert_enabled: b
|
||||||
run_agent_with_retry(subtask_agent, subtask_prompt, config)
|
run_agent_with_retry(subtask_agent, subtask_prompt, config)
|
||||||
|
|
||||||
|
|
||||||
def validate_environment(args):
|
|
||||||
"""Validate required environment variables and dependencies.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
args: The parsed command line arguments
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
(expert_enabled, missing_expert_info): Tuple of bool indicating if expert is enabled, and list of missing expert info
|
|
||||||
"""
|
|
||||||
missing = []
|
|
||||||
provider = args.provider
|
|
||||||
expert_provider = args.expert_provider
|
|
||||||
|
|
||||||
# Check API keys based on provider
|
|
||||||
if provider == "anthropic":
|
|
||||||
if not os.environ.get('ANTHROPIC_API_KEY'):
|
|
||||||
missing.append('ANTHROPIC_API_KEY environment variable is not set')
|
|
||||||
elif provider == "openai":
|
|
||||||
if not os.environ.get('OPENAI_API_KEY'):
|
|
||||||
missing.append('OPENAI_API_KEY environment variable is not set')
|
|
||||||
elif provider == "openrouter":
|
|
||||||
if not os.environ.get('OPENROUTER_API_KEY'):
|
|
||||||
missing.append('OPENROUTER_API_KEY environment variable is not set')
|
|
||||||
elif provider == "openai-compatible":
|
|
||||||
if not os.environ.get('OPENAI_API_KEY'):
|
|
||||||
missing.append('OPENAI_API_KEY environment variable is not set')
|
|
||||||
if not os.environ.get('OPENAI_API_BASE'):
|
|
||||||
missing.append('OPENAI_API_BASE environment variable is not set')
|
|
||||||
|
|
||||||
expert_missing = []
|
|
||||||
# Check expert provider keys with fallback
|
|
||||||
if expert_provider == "anthropic":
|
|
||||||
expert_key_missing = not os.environ.get('EXPERT_ANTHROPIC_API_KEY')
|
|
||||||
fallback_available = expert_provider == provider and os.environ.get('ANTHROPIC_API_KEY')
|
|
||||||
if expert_key_missing and fallback_available:
|
|
||||||
os.environ['EXPERT_ANTHROPIC_API_KEY'] = os.environ['ANTHROPIC_API_KEY']
|
|
||||||
expert_key_missing = False
|
|
||||||
if expert_key_missing:
|
|
||||||
expert_missing.append('EXPERT_ANTHROPIC_API_KEY environment variable is not set')
|
|
||||||
|
|
||||||
elif expert_provider == "openai":
|
|
||||||
expert_key_missing = not os.environ.get('EXPERT_OPENAI_API_KEY')
|
|
||||||
fallback_available = expert_provider == provider and os.environ.get('OPENAI_API_KEY')
|
|
||||||
if expert_key_missing and fallback_available:
|
|
||||||
os.environ['EXPERT_OPENAI_API_KEY'] = os.environ['OPENAI_API_KEY']
|
|
||||||
expert_key_missing = False
|
|
||||||
if expert_key_missing:
|
|
||||||
expert_missing.append('EXPERT_OPENAI_API_KEY environment variable is not set')
|
|
||||||
|
|
||||||
elif expert_provider == "openrouter":
|
|
||||||
expert_key_missing = not os.environ.get('EXPERT_OPENROUTER_API_KEY')
|
|
||||||
fallback_available = expert_provider == provider and os.environ.get('OPENROUTER_API_KEY')
|
|
||||||
if expert_key_missing and fallback_available:
|
|
||||||
os.environ['EXPERT_OPENROUTER_API_KEY'] = os.environ['OPENROUTER_API_KEY']
|
|
||||||
expert_key_missing = False
|
|
||||||
if expert_key_missing:
|
|
||||||
expert_missing.append('EXPERT_OPENROUTER_API_KEY environment variable is not set')
|
|
||||||
|
|
||||||
elif expert_provider == "openai-compatible":
|
|
||||||
expert_key_missing = not os.environ.get('EXPERT_OPENAI_API_KEY')
|
|
||||||
fallback_available = expert_provider == provider and os.environ.get('OPENAI_API_KEY')
|
|
||||||
if expert_key_missing and fallback_available:
|
|
||||||
os.environ['EXPERT_OPENAI_API_KEY'] = os.environ['OPENAI_API_KEY']
|
|
||||||
expert_key_missing = False
|
|
||||||
if expert_key_missing:
|
|
||||||
expert_missing.append('EXPERT_OPENAI_API_KEY environment variable is not set')
|
|
||||||
|
|
||||||
expert_base_missing = not os.environ.get('EXPERT_OPENAI_API_BASE')
|
|
||||||
base_fallback_available = expert_provider == provider and os.environ.get('OPENAI_API_BASE')
|
|
||||||
if expert_base_missing and base_fallback_available:
|
|
||||||
os.environ['EXPERT_OPENAI_API_BASE'] = os.environ['OPENAI_API_BASE']
|
|
||||||
expert_base_missing = False
|
|
||||||
if expert_base_missing:
|
|
||||||
expert_missing.append('EXPERT_OPENAI_API_BASE environment variable is not set')
|
|
||||||
|
|
||||||
|
|
||||||
# If main keys missing, we must exit immediately
|
|
||||||
if missing:
|
|
||||||
print_error("Missing required dependencies:")
|
|
||||||
for item in missing:
|
|
||||||
print_error(f"- {item}")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# If expert keys missing, we disable expert tools instead of exiting
|
|
||||||
expert_enabled = True
|
|
||||||
if expert_missing:
|
|
||||||
expert_enabled = False
|
|
||||||
|
|
||||||
return expert_enabled, expert_missing
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main entry point for the ra-aid command line tool."""
|
"""Main entry point for the ra-aid command line tool."""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue