NimrodDev commited on
Commit
a6ff47d
·
1 Parent(s): 297c727
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -9,6 +9,8 @@ import logging
9
  import os
10
  import random
11
  import re
 
 
12
  from flask import Flask, request, jsonify
13
  from supabase import create_client, Client
14
 
@@ -20,6 +22,18 @@ SUPABASE_URL = os.getenv("SUPABASE_URL")
20
  SUPABASE_KEY = os.getenv("SUPABASE_KEY")
21
  supabase: Optional[Client] = create_client(SUPABASE_URL, SUPABASE_KEY) if SUPABASE_URL else None
22
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  # ---------- 20 000+ INSTANCES ----------
24
  REPLIES: dict[str, list[str]] = {}
25
  def add(key: str, *templates: str) -> None:
 
9
  import os
10
  import random
11
  import re
12
+ from typing import Optional
13
+
14
  from flask import Flask, request, jsonify
15
  from supabase import create_client, Client
16
 
 
22
  SUPABASE_KEY = os.getenv("SUPABASE_KEY")
23
  supabase: Optional[Client] = create_client(SUPABASE_URL, SUPABASE_KEY) if SUPABASE_URL else None
24
 
25
+ # ---------- db helpers ----------
26
+ def save_msg(user: str, text: str, role: str = "assistant") -> None:
27
+ """Persist a single chat turn."""
28
+ if not supabase:
29
+ return
30
+ try:
31
+ supabase.table("chat_memory").insert(
32
+ {"user_phone": user, "role": role.lower(), "message": text}
33
+ ).execute()
34
+ except Exception as exc:
35
+ log.warning("db write: %s", exc)
36
+
37
  # ---------- 20 000+ INSTANCES ----------
38
  REPLIES: dict[str, list[str]] = {}
39
  def add(key: str, *templates: str) -> None: