#!/usr/bin/env python3
"""
Test: Does tool count affect local proxy behavior?
"""

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

from openai import OpenAI
from slack_bot.llm.gemini import get_system_instruction
from slack_bot.tools.groups import get_tool_preset

client = OpenAI(
    api_key="sk-457cbcd2e0a4467e90db1af0ae65748e",
    base_url="http://127.0.0.1:8045/v1"
)

system_prompt = get_system_instruction()
test_message = "今天睡得怎么样？"

print("=" * 80)
print("Tool Count Impact Test")
print("=" * 80)

modes = [
    ("light", 6),
    ("standard", 10),
    ("full", 15),
    ("all", 21),
]

for mode_name, expected_count in modes:
    tools, funcs = get_tool_preset(mode_name)
    actual_count = len(tools)

    print(f"\n{mode_name.upper()} mode ({actual_count} tools)")
    print("-" * 80)

    try:
        response = client.chat.completions.create(
            model="gemini-3-pro-high",
            messages=[
                {"role": "system", "content": system_prompt},
                {"role": "user", "content": test_message}
            ],
            tools=tools
        )

        msg = response.choices[0].message
        finish = response.choices[0].finish_reason
        has_content = bool(msg.content and msg.content.strip())
        has_tools = bool(msg.tool_calls)

        if has_tools:
            status = "✅ WORKS"
            detail = f"tool_calls={len(msg.tool_calls)}"
        elif has_content:
            status = "⚠️  TEXT"
            detail = f"text={len(msg.content)} chars"
        else:
            status = "❌ EMPTY"
            detail = f"finish={finish}"

        print(f"  Result: {status} ({detail})")

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

print("\n" + "=" * 80)
print("CONCLUSION:")
print("=" * 80)
print("If all modes fail equally:")
print("  → Tool count doesn't matter")
print("  → The proxy's function calling is fundamentally broken")
print("\nIf lighter modes work better:")
print("  → Tool count does matter")
print("  → The proxy has a limit on tool schema size")
print("=" * 80)
