CoolFace
Apppublic

monish563/NU-KIOSK-API

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
staff_support.py54 linesDownload Raw Back to tools
1"""Blueprint mapping administrative topics to the right staff contacts."""2 3from __future__ import annotations4 5import re6from typing import Any, List7 8from .base import AnalysisContext, Blueprint, BlueprintResult, Fact9 10 11class StaffSupportBlueprint(Blueprint):12    """Suggest staff contacts for administrative questions."""13 14    name = "staff_support"15 16    def run(self, context: AnalysisContext, **kwargs: Any) -> BlueprintResult:17        query = (kwargs.get("topic") or kwargs.get("need") or kwargs.get("keyword") or "").strip()18        if not query:19            return BlueprintResult(self.name, kwargs, facts=[], notes=["Let me know what kind of help you need (e.g., reimbursements, travel, advising)."])20 21        staff = context.catalog.try_get("staff")22        if not staff:23            return BlueprintResult(self.name, kwargs, facts=[], notes=["Staff directory is unavailable right now."])24 25        query_terms = [term for term in re.split(r"[^a-z0-9]+", query.lower()) if term]26        matches = []27        for row in staff.records:28            haystack = " ".join(str(row.get(field, "")).lower() for field in ("Role", "Title"))29            if all(term in haystack for term in query_terms):30                matches.append(row)31 32        facts: List[Fact] = []33        origin = staff.origin34        for row in matches:35            facts.append(36                Fact(37                    subject=row.get("Name", "Unknown"),38                    predicate="staff_support",39                    value={40                        "title": row.get("Title"),41                        "role": row.get("Role"),42                        "location": row.get("Room Location"),43                    },44                    source=origin,45                    confidence=0.85,46                )47            )48 49        notes: List[str] = []50        if not facts:51            notes.append(f"I couldn't find a staff contact that mentions '{query}'.")52 53        return BlueprintResult(self.name, kwargs, facts=facts, notes=notes)54