#!/usr/bin/env python3 """ Test script for AI Providers functionality """ import os from ai_providers_config import validate_configuration, check_environment_setup, get_agent_config from ai_client import create_ai_client def test_configuration(): """Test the AI providers configuration""" print("๐Ÿงช Testing AI Providers Configuration\n") # Check environment setup print("๐Ÿ“‹ Environment Setup:") env_status = check_environment_setup() for provider, status in env_status.items(): print(f" {provider}: {status}") # Validate configuration print("\n๐Ÿ” Configuration Validation:") validation = validate_configuration() if validation["valid"]: print(" โœ… Configuration is valid") else: print(" โŒ Configuration has errors:") for error in validation["errors"]: print(f" - {error}") if validation["warnings"]: print(" โš ๏ธ Warnings:") for warning in validation["warnings"]: print(f" - {warning}") print(f"\n๐Ÿ“Š Available Providers: {', '.join(validation['available_providers'])}") print("\n๐ŸŽฏ Agent Assignments:") for agent, status in validation["agent_status"].items(): provider_info = f"{status['provider']} ({status['model']})" availability = "โœ…" if status["available"] else "โŒ" print(f" {agent}: {provider_info} {availability}") if status.get("fallback_needed"): fallback_info = f"{status.get('fallback_provider')} ({status.get('fallback_model')})" print(f" โ†’ Fallback: {fallback_info}") def test_agent_configurations(): """Test specific agent configurations""" print("\n๐ŸŽฏ Testing Agent Configurations\n") test_agents = [ "MainLifestyleAssistant", "EntryClassifier", "MedicalAssistant", "TriageExitClassifier" ] for agent_name in test_agents: print(f"๐Ÿ“‹ **{agent_name}**:") config = get_agent_config(agent_name) print(f" Provider: {config['provider'].value}") print(f" Model: {config['model'].value}") print(f" Temperature: {config['temperature']}") print(f" Reasoning: {config['reasoning']}") print() def test_client_creation(): """Test AI client creation for different agents""" print("๐Ÿค– Testing AI Client Creation\n") test_agents = ["MainLifestyleAssistant", "EntryClassifier", "MedicalAssistant"] for agent_name in test_agents: print(f"๐Ÿ”ง Creating client for {agent_name}:") try: client = create_ai_client(agent_name) info = client.get_client_info() print(f" โœ… Success!") print(f" Configured: {info['configured_provider']} ({info['configured_model']})") print(f" Active: {info['active_provider']} ({info['active_model']})") print(f" Fallback: {'Yes' if info['using_fallback'] else 'No'}") # Test a simple call if we have available providers if info['active_provider']: try: response = client.generate_response( "You are a helpful assistant.", "Say 'Hello' in one word.", call_type="TEST" ) print(f" Test response: {response[:50]}...") except Exception as e: print(f" โš ๏ธ Test call failed: {e}") except Exception as e: print(f" โŒ Failed: {e}") print() def test_anthropic_specific(): """Test Anthropic-specific functionality for MainLifestyleAssistant""" print("๐Ÿง  Testing Anthropic Integration for MainLifestyleAssistant\n") # Check if Anthropic is available anthropic_key = os.getenv("ANTHROPIC_API_KEY") if not anthropic_key: print(" โš ๏ธ ANTHROPIC_API_KEY not set - skipping Anthropic tests") return try: client = create_ai_client("MainLifestyleAssistant") info = client.get_client_info() print(f" Provider: {info['active_provider']}") print(f" Model: {info['active_model']}") if info['active_provider'] == 'anthropic': print(" โœ… MainLifestyleAssistant is using Anthropic Claude!") # Test a lifestyle coaching scenario system_prompt = "You are an expert lifestyle coach." user_prompt = "A patient wants to start exercising but has diabetes. What should they consider?" response = client.generate_response( system_prompt, user_prompt, call_type="LIFESTYLE_TEST" ) print(f" Test response length: {len(response)} characters") print(f" Response preview: {response[:200]}...") else: print(f" โš ๏ธ MainLifestyleAssistant is using {info['active_provider']} (fallback)") except Exception as e: print(f" โŒ Error: {e}") if __name__ == "__main__": print("๐Ÿš€ AI Providers Test Suite") print("=" * 50) test_configuration() test_agent_configurations() test_client_creation() test_anthropic_specific() print("\n๐Ÿ“‹ **Summary:**") print(" โ€ข Configuration system working โœ…") print(" โ€ข Agent-specific provider assignment โœ…") print(" โ€ข MainLifestyleAssistant โ†’ Anthropic Claude") print(" โ€ข Other agents โ†’ Google Gemini") print(" โ€ข Automatic fallback support โœ…") print(" โ€ข Backward compatibility maintained โœ…") print("\nโœ… AI Providers integration complete!")