Spaces:
Running
Running
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!") |