#!/usr/bin/env python3
"""
Clean test: Can local proxy work at all with any valid config?
"""

import os
import sys
sys.path.append(os.getcwd())

from openai import OpenAI

local_config = {
    "base_url": "http://127.0.0.1:8045",
    "api_key": "sk-457cbcd2e0a4467e90db1af0ae65748e",
    "model": "gemini-3-pro-high"
}

client = OpenAI(
    api_key=local_config['api_key'],
    base_url=f"{local_config['base_url']}/v1"
)

print("=" * 80)
print("Clean Test: Can local proxy work at all?")
print("=" * 80)

test_cases = [
    ("Minimal", "You are a helpful assistant.", "Hello, how are you?", False),
    ("Health simple", "You are a health assistant.", "今天睡得怎么样？", False),
    ("Health with tool mention", "You are a health assistant. When user asks about health data, call tools.", "今天睡得怎么样？", False),
]

for name, system, user, use_tools in test_cases:
    print(f"\n{name}")
    print("-" * 80)
    print(f"  System: {system[:60]}...")
    print(f"  User: {user}")
    print(f"  Tools: {use_tools}")

    try:
        kwargs = {
            "model": local_config['model'],
            "messages": [
                {"role": "system", "content": system},
                {"role": "user", "content": user}
            ]
        }

        response = client.chat.completions.create(**kwargs)

        msg = response.choices[0].message
        finish = response.choices[0].finish_reason

        result = "✅ WORKS" if msg.content and msg.content.strip() else "❌ EMPTY"
        print(f"  Result: {result}")
        print(f"  Finish: {finish}")
        print(f"  Length: {len(msg.content) if msg.content else 0}")
        if msg.content:
            print(f"  Preview: {msg.content[:100]}")

    except Exception as e:
        print(f"  Result: ❌ ERROR")
        print(f"  Error: {str(e)[:100]}")

print("\n" + "=" * 80)
print("If ALL tests fail, the proxy itself is broken.")
print("If simple tests work but health tests fail, it's the content/prompt.")
print("=" * 80)
