#!/usr/bin/env python3
"""
Final test: What happens when we provide ONE simple tool?
"""

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

from openai import OpenAI

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

# Simple tool definition
simple_tool = {
    "type": "function",
    "function": {
        "name": "get_sleep_data",
        "description": "Get sleep data",
        "parameters": {
            "type": "object",
            "properties": {
                "date": {"type": "string", "description": "Date"}
            },
            "required": ["date"]
        }
    }
}

print("=" * 80)
print("Test: Simple system prompt + 1 tool")
print("=" * 80)

response = client.chat.completions.create(
    model="gemini-3-pro-high",
    messages=[
        {"role": "system", "content": "You are a health assistant. Call tools to get data."},
        {"role": "user", "content": "今天睡得怎么样？"}
    ],
    tools=[simple_tool]
)

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

print(f"Finish reason: {finish}")
print(f"Content: {repr(msg.content)}")
print(f"Tool calls: {msg.tool_calls}")

if msg.tool_calls:
    print(f"\n✅ Tool call successful!")
    for tc in msg.tool_calls:
        print(f"  - {tc.function.name}({tc.function.arguments})")
elif msg.content:
    print(f"\n⚠️  No tool call, but has content")
else:
    print(f"\n❌ Empty response")

print("\n" + "=" * 80)
print("KEY QUESTION: Does providing tool definition help?")
print("=" * 80)
