Spaces:
Sleeping
Sleeping
| # app/policy.py | |
| from __future__ import annotations | |
| import os, re | |
| # --- Topic detection (very lightweight, fast) --- | |
| CAFE_KEYWORDS = [ | |
| "menu","order","item","dish","pizza","burger","salad","pasta","vegan","gluten", | |
| "price","special","deal","offer","hours","open","close","time","location","address", | |
| "book","reserve","reservation","table","party","pickup","delivery","takeout","payment", | |
| "futurecafe","future cafe","future-cafe","café","coffee","drinks","beverage","side" | |
| ] | |
| _kw_re = re.compile(r"|".join([re.escape(k) for k in CAFE_KEYWORDS]), re.I) | |
| SMALLTALK = r"\b(hi|hello|hey|good\s+(morning|afternoon|evening)|thanks|thank you|bye|goodbye)\b" | |
| _smalltalk_re = re.compile(SMALLTALK, re.I) | |
| def is_cafe_topic(text: str) -> bool: | |
| return bool(text and _kw_re.search(text)) | |
| def is_smalltalk(text: str) -> bool: | |
| return bool(text and _smalltalk_re.search(text)) | |
| def unrelated_limit() -> int: | |
| """How many off-topic turns allowed before ending.""" | |
| try: | |
| n = int(os.getenv("CAFE_UNRELATED_LIMIT", "3")) | |
| return max(1, min(5, n)) | |
| except Exception: | |
| return 3 | |
| # --- Messages --- | |
| POLITE_REFUSAL = ( | |
| "I’m here to help with FutureCafe—menu, hours, reservations, and orders. " | |
| "Could you ask something about the restaurant?" | |
| ) | |
| POLITE_REFUSAL_2 = ( | |
| "To keep things focused, I can only help with FutureCafe. " | |
| "Ask me about our menu, hours, or booking a table." | |
| ) | |
| def end_message() -> str: | |
| return ("I’m only able to help with FutureCafe topics. " | |
| "Let’s end this chat for now. If you need menu, hours, or reservations, " | |
| "message me again anytime.") |