debate-bots/test_provider.py
2025-11-11 19:49:58 -07:00

59 lines
1.8 KiB
Python
Executable File

#!/usr/bin/env python3
"""Simple test script to verify OpenRouter provider works."""
import sys
from src.providers.openrouter import OpenRouterProvider
from rich.console import Console
console = Console()
def test_openrouter():
"""Test basic OpenRouter functionality."""
console.print("[cyan]Testing OpenRouter Provider[/cyan]\n")
# Get API key and model from user
api_key = input("Enter your OpenRouter API key: ").strip()
model = input("Enter model (or press Enter for anthropic/claude-3-haiku): ").strip()
if not model:
model = "anthropic/claude-3-haiku"
console.print(f"\n[yellow]Testing with model: {model}[/yellow]")
try:
# Create provider
console.print("[blue]Creating provider...[/blue]")
provider = OpenRouterProvider(model=model, api_key=api_key)
# Validate config
console.print("[blue]Validating configuration...[/blue]")
provider.validate_config()
console.print("[green]✓ Configuration valid[/green]")
# Test simple generation
console.print("\n[blue]Sending test message...[/blue]")
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Say hello in one sentence."},
]
with console.status("[yellow]Waiting for response...[/yellow]"):
response = provider.generate_response(messages)
console.print("\n[green]✓ Success! Response received:[/green]")
console.print(f"[dim]{response}[/dim]\n")
return True
except Exception as e:
console.print(f"\n[red]✗ Error:[/red] {str(e)}")
import traceback
console.print(f"[dim]{traceback.format_exc()}[/dim]")
return False
if __name__ == "__main__":
success = test_openrouter()
sys.exit(0 if success else 1)