#!/usr/bin/env python3
import os, sys
sys.path.append('.')
os.environ['DEBUG_GEMINI_PAYLOAD'] = 'true'

from health.utils.env_loader import load_env_with_extras
from slack_bot.llm.gemini import GeminiLLM
from slack_bot.tools.registry import TOOLS_SCHEMA
import json

load_env_with_extras()

print("\n========== TEST 1: WITHOUT TOOLS ==========")
llm1 = GeminiLLM()
response1, _ = llm1.generate_response('今天睡得怎么样？', [], tools=None)

with open('debug_response.json') as f:
    r1 = json.load(f)

print(f"Response length: {len(response1) if response1 else 0}")
print(f"Finish reason: {r1.get('finish_reason')}")
print(f"Has content: {bool(response1)}")

print("\n========== TEST 2: WITH TOOLS ==========")
llm2 = GeminiLLM()
response2, _ = llm2.generate_response('今天睡得怎么样？', [], tools=TOOLS_SCHEMA)

with open('debug_response.json') as f:
    r2 = json.load(f)

print(f"Response length: {len(response2) if response2 else 0}")
print(f"Finish reason: {r2.get('finish_reason')}")
print(f"Has content: {bool(response2)}")

print("\n========== COMPARISON ==========")
print(f"Without tools: {'✅ Works' if response1 else '❌ Empty'}")
print(f"With tools:    {'✅ Works' if response2 else '❌ Empty'}")

if not response2 and response1:
    print("\n🔍 CONCLUSION: Tools parameter causes empty response")
    print("   This confirms the proxy has issues with function calling")
