AI_Personas / tests /test_api_connection.py
Claude
Fix example scripts and add API testing utilities
76c6f71 unverified
"""
Quick test to verify Anthropic API connection
"""
import sys
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent.parent))
from src.llm.anthropic_client import AnthropicClient
print("\n" + "=" * 70)
print("Testing Anthropic API Connection")
print("=" * 70 + "\n")
try:
# Initialize client
print("1. Initializing Anthropic client...")
client = AnthropicClient()
print(f" βœ“ Client initialized")
print(f" Model: {client.model}")
print(f" Max tokens: {client.max_tokens}")
print(f" Temperature: {client.temperature}")
# Test connection
print("\n2. Testing API connection...")
if client.test_connection():
print(" βœ“ API connection successful!")
else:
print(" βœ— API connection failed")
exit(1)
# Test a simple query
print("\n3. Testing a simple query...")
response = client.generate_response(
system_prompt="You are a helpful assistant. Be brief.",
user_message="Say 'Hello from the AI Personas system!' and nothing else.",
max_tokens=50,
)
print(f" Response: {response}")
print("\n" + "=" * 70)
print("βœ“ All API tests passed! System is ready to use.")
print("=" * 70 + "\n")
except Exception as e:
print(f"\nβœ— Error: {e}\n")
exit(1)