#!/usr/bin/env python3
"""
测试不同模型，找出可用的模型
"""

import requests
import time

BASE_URL = "https://oneapi.gongjulian.cn/v1"
API_KEY = "sk-lB2Fc9ssY5UuwmiV5dD441F997364d29Be547e008dF5Cf41"

# 可选模型列表
MODELS = [
    "deepseek-ai/deepseek-v3.2",
    "deepseek-ai/deepseek-r1",
    "minimaxai/minimax-m2.1",
    "z-ai/glm4.7",
]

def test_model(model_id):
    """测试单个模型"""
    url = f"{BASE_URL}/chat/completions"
    headers = {
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    }

    payload = {
        "model": model_id,
        "messages": [
            {
                "role": "user",
                "content": "你好，请简单回复"
            }
        ],
        "max_tokens": 20,
        "temperature": 0.1
    }

    print(f"\n测试模型: {model_id}")
    print("-" * 40)

    try:
        start_time = time.time()
        response = requests.post(url, headers=headers, json=payload, timeout=30)
        elapsed = time.time() - start_time

        print(f"  状态码: {response.status_code}")
        print(f"  耗时: {elapsed:.2f}秒")

        if response.status_code == 200:
            result = response.json()
            content = result.get("choices", [{}])[0].get("message", {}).get("content", "")
            print(f"  响应: {content[:100]}")
            return True
        else:
            print(f"  错误: {response.text[:200] if response.text else '无响应'}")
            return False

    except requests.exceptions.Timeout:
        print(f"  超时")
        return False
    except Exception as e:
        print(f"  错误: {e}")
        return False

if __name__ == "__main__":
    print("测试不同模型的可用性")
    print(f"API: {BASE_URL}")
    print("=" * 50)

    results = {}
    for model in MODELS:
        results[model] = test_model(model)

    print("\n" + "=" * 50)
    print("测试结果")
    print("=" * 50)
    for model, success in results.items():
        status = "可用" if success else "不可用"
        print(f"{model}: {status}")

    available = [m for m, s in results.items() if s]
    if available:
        print(f"\n建议使用的模型: {available[0]}")
