Spaces:
Sleeping
Sleeping
Remove supabase
Browse files- db_client.py +0 -31
db_client.py
CHANGED
@@ -1,31 +0,0 @@
|
|
1 |
-
from supabase import create_client, Client
|
2 |
-
import os
|
3 |
-
import json
|
4 |
-
from dotenv import load_dotenv
|
5 |
-
|
6 |
-
load_dotenv()
|
7 |
-
|
8 |
-
# Initialize Supabase client
|
9 |
-
supabase: Client = create_client(os.getenv("SUPABASE_URL"), os.getenv("SUPABASE_KEY"))
|
10 |
-
|
11 |
-
def get_user_history(user_id):
|
12 |
-
response = supabase.table("history").select("messages").eq("user", user_id).order("created_at", desc=True).limit(1).execute()
|
13 |
-
if response.data:
|
14 |
-
return response.data[0]['messages']
|
15 |
-
return []
|
16 |
-
|
17 |
-
def update_user_history(user_id, new_history):
|
18 |
-
# Filter out messages with image type
|
19 |
-
filtered_history = [
|
20 |
-
message for message in new_history
|
21 |
-
if not (message["role"] == "user" and
|
22 |
-
isinstance(message["content"], list) and
|
23 |
-
any(item.get("type") == "image" for item in message["content"]))
|
24 |
-
]
|
25 |
-
|
26 |
-
# Insert the filtered history into the database
|
27 |
-
supabase.table("history").insert({"user": user_id, "messages": filtered_history}).execute()
|
28 |
-
|
29 |
-
def delete_user_history(user_id):
|
30 |
-
response = supabase.table("history").delete().eq("user", user_id).execute()
|
31 |
-
return response.data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|