File size: 5,865 Bytes
5933c22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/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!")