Spaces:
Runtime error
Runtime error
File size: 3,246 Bytes
3696fe2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
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() |