Download src/rag/fallback_handler.py from danishk84/NovaGuide: direct link, hf CLI and curl.
- Browser
- Download file 2.56 kB
-
https://huggingface.co/spaces/danishk84/NovaGuide/resolve/main/src/rag/fallback_handler.py
- Command line
-
hf download hf://spaces/danishk84/NovaGuide/src/rag/fallback_handler.py
-
curl -L -o fallback_handler.py https://huggingface.co/spaces/danishk84/NovaGuide/resolve/main/src/rag/fallback_handler.py
2.56 kB
| """Passenger-friendly deterministic fallback responses.""" | |
| from __future__ import annotations | |
| from typing import Any | |
| class FallbackHandler: | |
| """Create safe fallback payloads with a recommended next action.""" | |
| def _payload( | |
| answer: str, reason: str, notes: list[str], action: str | |
| ) -> dict[str, Any]: | |
| return { | |
| "answer": answer, | |
| "fallback_triggered": True, | |
| "reason": reason, | |
| "safety_notes": notes, | |
| "recommended_action": action, | |
| } | |
| def low_confidence(self, query: str, reason: str | None = None) -> dict[str, Any]: | |
| return self._payload( | |
| "I’m not confident enough to give a reliable airport answer. " | |
| "Please rephrase your question and include the terminal or service you need.", | |
| reason or "Low confidence", | |
| ["No airport fact was inferred without sufficient evidence."], | |
| "Rephrase with a terminal, level, or service name.", | |
| ) | |
| def unsupported_query( | |
| self, query: str, reason: str | None = None | |
| ) -> dict[str, Any]: | |
| return self._payload( | |
| "That request is outside NovaGuide’s BER passenger-assistance scope. " | |
| "Please ask about airport facilities, accessibility, transport, baggage, " | |
| "check-in, or security.", | |
| reason or "Unsupported query", | |
| ["Unsupported requests are not guessed."], | |
| "Ask a BER airport passenger-assistance question.", | |
| ) | |
| def flight_status_unavailable(self, query: str) -> dict[str, Any]: | |
| return self._payload( | |
| "Live flight status, gate changes, delays and boarding information are not " | |
| "available from the static NovaGuide knowledge base. Please check the official " | |
| "BER flight displays or your airline for the latest information.", | |
| "Verified live flight data is unavailable", | |
| ["No live flight claim was generated."], | |
| "Check official BER displays or the operating airline.", | |
| ) | |
| def system_unavailable(self, query: str, component: str) -> dict[str, Any]: | |
| return self._payload( | |
| f"NovaGuide cannot verify this information because {component} is currently " | |
| "unavailable. Please use official BER information or ask airport staff.", | |
| f"{component} unavailable", | |
| ["No answer was generated from unavailable evidence."], | |
| "Check official BER information or ask airport staff.", | |
| ) | |