First_agent_template / debug_test.py
kumar4372's picture
openai key
3696fe2
import os
import pytz
from tools.nlu_tool import extract_intent_and_slots
from tools.scheduler import find_common_slots
from datetime import datetime
from smolagents import OpenAIServerModel
def test_timezone_function():
"""Test the timezone functionality"""
try:
tz = pytz.timezone('America/New_York')
local_time = datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
print("Timezone test passed:", local_time)
except Exception as e:
print("Timezone test failed:", str(e))
def test_nlu():
"""Test the NLU functionality"""
try:
# Test with an amount in yen
test_text = "I need to transfer ¥30,000"
result = extract_intent_and_slots(test_text)
print("NLU test result (amount):", result)
# Test with a date/time
test_text_2 = "Schedule for tomorrow at 2pm"
result_2 = extract_intent_and_slots(test_text_2)
print("NLU test result (schedule):", result_2)
except Exception as e:
print("NLU test failed:", str(e))
def test_scheduler():
"""Test the scheduler functionality"""
try:
# Create proper datetime objects in Asia/Tokyo timezone
import dateparser
from datetime import datetime, timedelta
tz = pytz.timezone('Asia/Tokyo')
settings = {'TIMEZONE': 'Asia/Tokyo', 'RETURN_AS_TIMEZONE_AWARE': True}
tomorrow = datetime.now() + timedelta(days=1)
start_str = f"tomorrow 09:00"
end_str = f"tomorrow 12:00"
start = dateparser.parse(start_str, settings=settings)
end = dateparser.parse(end_str, settings=settings)
test_windows = [
{'start': start, 'end': end}
]
result = find_common_slots(test_windows)
print("Scheduler test result:", result)
except Exception as e:
print("Scheduler test failed:", str(e))
def test_openai_connection():
"""Test the OpenAI API connection"""
try:
print("Testing OpenAI API connection...")
openai_api_key = os.getenv('OPENAI_API_KEY')
if not openai_api_key:
print("❌ Error: OPENAI_API_KEY environment variable is not set")
return
model = OpenAIServerModel(
api_key=openai_api_key,
model_id="gpt-5-mini-2025-08-07",
max_tokens=50,
temperature=0.5,
)
# Try a simple chat completion to test the connection
test_prompt = "Say 'Hello, the API is working!'"
try:
response = model.generate_text(test_prompt)
print("✅ OpenAI API Test Response:", response)
except Exception as e:
print("❌ API Call Error:", str(e))
print("Error details:", str(type(e).__name__))
except Exception as e:
print("❌ OpenAI Setup Error:", str(e))
def main():
print("Starting debug tests...")
print("\n1. Testing OpenAI API connection:")
test_openai_connection()
print("\n2. Testing timezone functionality:")
test_timezone_function()
print("\n3. Testing NLU:")
test_nlu()
print("\n4. Testing scheduler:")
test_scheduler()
if __name__ == "__main__":
main()