File size: 2,563 Bytes
7ca0188
 
 
 
 
 
 
 
 
 
 
830c01e
 
 
 
 
 
 
 
 
 
7ca0188
 
 
830c01e
 
 
 
7ca0188
 
 
830c01e
 
 
7ca0188
830c01e
 
 
 
 
7ca0188
 
 
 
 
830c01e
 
 
 
 
7ca0188
 
 
 
 
830c01e
 
 
 
7ca0188
 
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
"""Passenger-friendly deterministic fallback responses."""

from __future__ import annotations

from typing import Any


class FallbackHandler:
    """Create safe fallback payloads with a recommended next action."""

    @staticmethod
    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.",
        )