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