Spaces:
Sleeping
Sleeping
from typing import List, Dict | |
from core.constants import Tables | |
from core.interface.supabase_client import supabase_config, async_supabase_client | |
from core.schemas.chat import ChatModel | |
class ChatDataSource: | |
async def fetch_previous_chats(user_id: str) -> List[Dict]: | |
supabase = await async_supabase_client(supabase_config) | |
response = await supabase.table(Tables.AI_CHAT_TABLE) \ | |
.select('*') \ | |
.eq('user_id', user_id) \ | |
.order('datetime', desc=True) \ | |
.execute() | |
return response.data | |
async def send_new_chat(chat: ChatModel): | |
supabase = await async_supabase_client(supabase_config) | |
response = await supabase.table(Tables.AI_CHAT_TABLE) \ | |
.insert(chat.to_json()) \ | |
.execute() | |
return response.data | |