"""Test Milestone 1: Provider router works with at least one provider."""
import asyncio
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

async def test_providers():
    from backend.providers import call_llm

    test_messages = [
        {"role": "user", "content": "Reply with exactly: THIRDEYE_OK"}
    ]

    # Test 1: fast_small (should use Groq 8B)
    print("Testing fast_small (Groq 8B / Cerebras 8B)...")
    try:
        result = await call_llm("fast_small", test_messages, max_tokens=50)
        print(f"  ✅ fast_small → {result['provider']}/{result['model']}")
        print(f"     Response: {result['content'][:80]}")
    except Exception as e:
        print(f"  ❌ fast_small failed: {e}")

    # Test 2: fast_large (should use Groq 70B)
    print("Testing fast_large (Groq/Cerebras 70B)...")
    try:
        result = await call_llm("fast_large", test_messages, max_tokens=50)
        print(f"  ✅ fast_large → {result['provider']}/{result['model']}")
        print(f"     Response: {result['content'][:80]}")
    except Exception as e:
        print(f"  ❌ fast_large failed: {e}")

    # Test 3: reasoning (should use SambaNova 405B)
    print("Testing reasoning (SambaNova 405B / OpenRouter Nemotron)...")
    try:
        result = await call_llm("reasoning", test_messages, max_tokens=50)
        print(f"  ✅ reasoning → {result['provider']}/{result['model']}")
        print(f"     Response: {result['content'][:80]}")
    except Exception as e:
        print(f"  ❌ reasoning failed: {e}")

    # Test 4: JSON mode
    print("Testing JSON mode...")
    try:
        json_messages = [
            {"role": "system", "content": "You respond only in valid JSON."},
            {"role": "user", "content": 'Return: {"status": "ok", "test": true}'},
        ]
        result = await call_llm("fast_small", json_messages, max_tokens=100)
        print(f"  ✅ JSON mode → {result['provider']}/{result['model']}")
        print(f"     Response: {result['content'][:120]}")
    except Exception as e:
        print(f"  ❌ JSON mode failed: {e}")

    print("\n🎉 MILESTONE 1 PASSED — At least one provider works per task type")

asyncio.run(test_providers())
