#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
简化版思考模式测试 - 快速验证

运行方式:
    cd D:/wx_work/sichuan_luqiao/LQAgentPlatform
    python utils_test/Model_Test/test_thinking_mode_simple.py
"""

import asyncio
import time
import sys
from pathlib import Path

project_root = Path(__file__).parent.parent.parent
sys.path.insert(0, str(project_root))

from foundation.ai.agent.generate.model_generate import generate_model_client


async def quick_test():
    """快速测试思考模式开关"""
    print("\n" + "=" * 60)
    print("快速测试: Qwen3.5 思考模式开关")
    print("=" * 60)

    # 测试 1: 默认禁用思考模式
    print("\n[Test 1] 默认禁用思考模式 (enable_thinking=False)")
    start = time.time()
    try:
        resp = await generate_model_client.get_model_generate_invoke(
            trace_id="test_quick_disabled",
            system_prompt="简洁回答",
            user_prompt="2+2=?",
            model_name="qwen3_5_35b_a3b",
            enable_thinking=False,
            timeout=60
        )
        elapsed = time.time() - start
        print(f"  ✅ 成功 ({elapsed:.2f}s): {resp[:50]}...")
        assert elapsed < 60, f"响应时间过长: {elapsed:.2f}s，思考模式可能未禁用"
    except Exception as e:
        print(f"  ❌ 失败: {e}")
        return False

    # 测试 2: 显式启用思考模式（可选，耗时较长）
    print("\n[Test 2] 显式启用思考模式 (enable_thinking=True) - 可选")
    print("  [跳过] 取消注释以下代码以运行")
    # start = time.time()
    # try:
    #     resp = await generate_model_client.get_model_generate_invoke(
    #         trace_id="test_quick_enabled",
    #         system_prompt="详细推理后回答",
    #         user_prompt="请解释勾股定理",
    #         model_name="qwen3_5_35b_a3b",
    #         enable_thinking=True,
    #         timeout=180
    #     )
    #     elapsed = time.time() - start
    #     print(f"  ✅ 成功 ({elapsed:.2f}s): {resp[:100]}...")
    # except Exception as e:
    #     print(f"  ❌ 失败: {e}")
    #     return False

    # 测试 3: 非 Qwen3.5 模型
    print("\n[Test 3] 非 Qwen3.5 模型")
    start = time.time()
    try:
        resp = await generate_model_client.get_model_generate_invoke(
            trace_id="test_quick_doubao",
            system_prompt="简洁回答",
            user_prompt="3+3=?",
            model_name="doubao-1.5-pro-256k",
            enable_thinking=False,  # 应被忽略
            timeout=30
        )
        elapsed = time.time() - start
        print(f"  ✅ 成功 ({elapsed:.2f}s): {resp[:50]}...")
    except Exception as e:
        print(f"  ❌ 失败: {e}")
        return False

    print("\n" + "=" * 60)
    print("🎉 所有快速测试通过！")
    print("=" * 60 + "\n")
    return True


if __name__ == "__main__":
    success = asyncio.run(quick_test())
    sys.exit(0 if success else 1)
