Update src/api/agent.py
Browse files- src/api/agent.py +80 -62
src/api/agent.py
CHANGED
|
@@ -519,78 +519,96 @@ def _rule_based_classify(question: str) -> Dict[str, str]:
|
|
| 519 |
|
| 520 |
def _hours_answer() -> str:
|
| 521 |
"""
|
| 522 |
-
Return a rich, day-aware library hours answer.
|
| 523 |
Always links to https://library.ku.ac.ae/hours for live schedule.
|
| 524 |
"""
|
| 525 |
from datetime import datetime, timezone, timedelta
|
| 526 |
# UAE is UTC+4
|
| 527 |
uae_now = datetime.now(timezone(timedelta(hours=4)))
|
| 528 |
-
day_num = uae_now.weekday() # 0=Mon β¦ 6=Sun
|
| 529 |
-
# Map to day name
|
| 530 |
day_names = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
|
| 531 |
-
today = day_names[
|
| 532 |
-
|
| 533 |
-
#
|
| 534 |
-
|
| 535 |
-
"
|
| 536 |
-
"
|
| 537 |
-
"
|
| 538 |
-
"
|
| 539 |
-
"
|
| 540 |
-
"
|
| 541 |
-
"
|
| 542 |
}
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
)
|
| 552 |
-
else:
|
| 553 |
-
today_line = f'π
<strong>Today ({today}):</strong> Check the live hours page.'
|
| 554 |
|
| 555 |
return (
|
| 556 |
-
|
| 557 |
-
f"{
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
"<strong>
|
| 561 |
-
"<span style='font-size:.
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
"<
|
| 565 |
-
"<
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
"<
|
| 569 |
-
"<
|
| 570 |
-
"
|
| 571 |
-
|
| 572 |
-
"
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
"
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
"<td style='padding:3px 0;font-weight:600;color:#16a34a'>8:00 AM β 7:00 PM</td></tr>"
|
| 581 |
-
"<tr><td style='padding:3px 12px 3px 0;color:#374151'>Thursday</td>"
|
| 582 |
-
"<td style='padding:3px 0;font-weight:600;color:#d97706'>8:00 AM β 4:00 PM</td></tr>"
|
| 583 |
-
"<tr><td style='padding:3px 12px 3px 0;color:#374151'>Friday</td>"
|
| 584 |
-
"<td style='padding:3px 0;font-weight:600;color:#dc2626'>Closed</td></tr>"
|
| 585 |
-
"<tr><td style='padding:3px 12px 3px 0;color:#374151'>Saturday</td>"
|
| 586 |
-
"<td style='padding:3px 0;font-weight:600;color:#16a34a'>12:00 PM β 8:00 PM</td></tr>"
|
| 587 |
-
"</table><br>"
|
| 588 |
-
|
| 589 |
-
# Warning + live link
|
| 590 |
-
"β οΈ <strong>Hours change during Ramadan, exam periods, and public holidays.</strong><br>"
|
| 591 |
-
f'Always check the live schedule: '
|
| 592 |
-
f'<a href="{LIBRARY_HOURS_URL}" target="_blank" style="font-weight:700;color:#003366">'
|
| 593 |
-
f'{LIBRARY_HOURS_URL}</a>'
|
| 594 |
)
|
| 595 |
|
| 596 |
|
|
|
|
| 519 |
|
| 520 |
def _hours_answer() -> str:
|
| 521 |
"""
|
| 522 |
+
Return a rich, day-aware library hours answer with correct Normal and Semester Break schedules.
|
| 523 |
Always links to https://library.ku.ac.ae/hours for live schedule.
|
| 524 |
"""
|
| 525 |
from datetime import datetime, timezone, timedelta
|
| 526 |
# UAE is UTC+4
|
| 527 |
uae_now = datetime.now(timezone(timedelta(hours=4)))
|
|
|
|
|
|
|
| 528 |
day_names = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
|
| 529 |
+
today = day_names[uae_now.weekday()]
|
| 530 |
+
|
| 531 |
+
# Normal hours (classes in session)
|
| 532 |
+
_NORMAL = {
|
| 533 |
+
"Monday": ("Open", "8:00 AM β 9:00 PM"),
|
| 534 |
+
"Tuesday": ("Open", "8:00 AM β 9:00 PM"),
|
| 535 |
+
"Wednesday": ("Open", "8:00 AM β 9:00 PM"),
|
| 536 |
+
"Thursday": ("Open", "8:00 AM β 5:00 PM"),
|
| 537 |
+
"Friday": ("Open", "7:30 AM β 12:30 PM"),
|
| 538 |
+
"Saturday": ("Closed", ""),
|
| 539 |
+
"Sunday": ("Open", "12:00 PM β 8:00 PM"),
|
| 540 |
}
|
| 541 |
+
# Semester break hours (classes not in session)
|
| 542 |
+
_BREAK = {
|
| 543 |
+
"Monday": ("Open", "8:00 AM β 4:00 PM"),
|
| 544 |
+
"Tuesday": ("Open", "8:00 AM β 4:00 PM"),
|
| 545 |
+
"Wednesday": ("Open", "8:00 AM β 4:00 PM"),
|
| 546 |
+
"Thursday": ("Open", "8:00 AM β 4:00 PM"),
|
| 547 |
+
"Friday": ("Open", "7:30 AM β 12:00 PM"),
|
| 548 |
+
"Saturday": ("Closed", ""),
|
| 549 |
+
"Sunday": ("Closed", ""),
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
def _day_row(day: str, status: str, hrs: str) -> str:
|
| 553 |
+
if status == "Closed":
|
| 554 |
+
color = "#dc2626"
|
| 555 |
+
label = "Closed"
|
| 556 |
+
elif "12:00 PM" in hrs or "12:30 PM" in hrs:
|
| 557 |
+
color = "#d97706"
|
| 558 |
+
label = hrs
|
| 559 |
+
else:
|
| 560 |
+
color = "#16a34a"
|
| 561 |
+
label = hrs
|
| 562 |
+
return (
|
| 563 |
+
f"<tr><td style='padding:3px 12px 3px 0;color:#374151'>{day}</td>"
|
| 564 |
+
f"<td style='padding:3px 0;font-weight:600;color:{color}'>{label}</td></tr>"
|
| 565 |
+
)
|
| 566 |
+
|
| 567 |
+
def _today_line(schedule: dict) -> str:
|
| 568 |
+
status, hrs = schedule.get(today, ("Unknown", ""))
|
| 569 |
+
if status == "Closed":
|
| 570 |
+
return (f'π
<strong>Today ({today}):</strong> '
|
| 571 |
+
f'<span style="color:#dc2626;font-weight:700">Closed</span>')
|
| 572 |
+
elif status == "Open":
|
| 573 |
+
return (f'π
<strong>Today ({today}):</strong> '
|
| 574 |
+
f'<span style="color:#16a34a;font-weight:700">Open</span> Β· {hrs}')
|
| 575 |
+
return f'π
<strong>Today ({today}):</strong> Check live hours page.'
|
| 576 |
+
|
| 577 |
+
def _schedule_table(schedule: dict) -> str:
|
| 578 |
+
rows = "".join(
|
| 579 |
+
_day_row(d, *schedule[d])
|
| 580 |
+
for d in ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
|
| 581 |
+
)
|
| 582 |
+
return (
|
| 583 |
+
"<table style='font-size:.85rem;border-collapse:collapse;width:100%;max-width:380px'>"
|
| 584 |
+
+ rows + "</table>"
|
| 585 |
)
|
|
|
|
|
|
|
| 586 |
|
| 587 |
return (
|
| 588 |
+
"Here are the <strong>Khalifa University Library</strong> hours:<br><br>"
|
| 589 |
+
f"{_today_line(_NORMAL)}<br>"
|
| 590 |
+
"<span style='font-size:.75rem;color:#6b7280'>(based on normal semester schedule β see note below)</span><br><br>"
|
| 591 |
+
|
| 592 |
+
"<strong>π Normal Hours</strong> "
|
| 593 |
+
"<span style='font-size:.78rem;color:#6b7280'>(when classes are in session)</span><br><br>"
|
| 594 |
+
+ _schedule_table(_NORMAL) +
|
| 595 |
+
|
| 596 |
+
"<br><br><strong>ποΈ Semester Break Hours</strong> "
|
| 597 |
+
"<span style='font-size:.78rem;color:#6b7280'>(when classes are not in session)</span><br><br>"
|
| 598 |
+
+ _schedule_table(_BREAK) +
|
| 599 |
+
|
| 600 |
+
"<br><br><strong>π Both campuses follow the same schedule:</strong><br>"
|
| 601 |
+
"<span style='font-size:.82rem;color:#6b7280'>"
|
| 602 |
+
"Main Campus Library Β· E Building Β· "
|
| 603 |
+
'<a href="tel:+97123124604">+971 2 312 4604</a><br>'
|
| 604 |
+
"Habshan Library Β· Building 5, SAN Campus Β· "
|
| 605 |
+
'<a href="tel:+97123123160">+971 2 312 3160</a>'
|
| 606 |
+
"</span><br><br>"
|
| 607 |
+
|
| 608 |
+
"β οΈ <strong>Hours change during Ramadan, public holidays, and exam periods.</strong> "
|
| 609 |
+
"Always check the live schedule for the most current times:<br>"
|
| 610 |
+
f'<a href="{LIBRARY_HOURS_URL}" target="_blank" '
|
| 611 |
+
f'style="font-weight:700;color:#003366">{LIBRARY_HOURS_URL}</a>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 612 |
)
|
| 613 |
|
| 614 |
|