Spaces:
Sleeping
Sleeping
File size: 2,065 Bytes
6981c56 | 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | thread_context = {}
def set_thread_id(thread_id: str):
thread_context["thread_id"] = thread_id
def get_thread_id():
return thread_context.get("thread_id", "unknown")
AI_ENABLED_CACHE = True
def set_ai_enabled(value: bool):
global AI_ENABLED_CACHE
AI_ENABLED_CACHE = bool(value)
def is_ai_enabled():
return AI_ENABLED_CACHE
CUSTOMER_AI_ENABLED_CACHE: dict[str, bool] = {}
def normalize_phone(phone: str | None) -> str:
return (phone or "").strip()
def set_customer_ai_enabled(phone: str | None, value: bool):
normalized_phone = normalize_phone(phone)
if not normalized_phone:
return
CUSTOMER_AI_ENABLED_CACHE[normalized_phone] = bool(value)
def set_customer_ai_enabled_for_phone(phone: str | None, value: bool):
set_customer_ai_enabled(phone, value)
def is_customer_ai_enabled(phone: str | None) -> bool:
normalized_phone = normalize_phone(phone)
if not normalized_phone:
return True
return CUSTOMER_AI_ENABLED_CACHE.get(normalized_phone, True)
def get_customer_ai_enabled(phone: str | None) -> bool:
return is_customer_ai_enabled(phone)
def remove_customer_ai_enabled(phone: str | None):
normalized_phone = normalize_phone(phone)
if normalized_phone:
CUSTOMER_AI_ENABLED_CACHE.pop(normalized_phone, None)
def load_customer_ai_enabled_cache(rows: list[dict]):
CUSTOMER_AI_ENABLED_CACHE.clear()
for row in rows or []:
phone = normalize_phone(row.get("phone") or row.get("thread_id"))
if not phone:
continue
CUSTOMER_AI_ENABLED_CACHE[phone] = bool(row.get("ai_enabled", True))
def get_customer_ai_enabled_cache():
return CUSTOMER_AI_ENABLED_CACHE.copy()
SYSTEM_PROMPT_VARIABLE_CACHE = ""
def set_system_prompt_variable(value: str | None):
global SYSTEM_PROMPT_VARIABLE_CACHE
SYSTEM_PROMPT_VARIABLE_CACHE = (value or "").strip()
def get_system_prompt_variable() -> str:
return SYSTEM_PROMPT_VARIABLE_CACHE
|