quivr/backend/repository/chat/create_chat.py

34 lines
836 B
Python
Raw Normal View History

from dataclasses import dataclass
2023-06-28 20:39:27 +03:00
from uuid import UUID
2023-06-28 20:39:27 +03:00
from logger import get_logger
from models.chat import Chat
from models.settings import get_supabase_db
logger = get_logger(__name__)
@dataclass
class CreateChatProperties:
name: str
def __init__(self, name: str):
self.name = name
2023-06-28 20:39:27 +03:00
def create_chat(user_id: UUID, chat_data: CreateChatProperties) -> Chat:
supabase_db = get_supabase_db()
# Chat is created upon the user's first question asked
logger.info(f"New chat entry in chats table for user {user_id}")
# Insert a new row into the chats table
new_chat = {
2023-06-28 20:39:27 +03:00
"user_id": str(user_id),
"chat_name": chat_data.name,
}
insert_response = supabase_db.create_chat(new_chat)
logger.info(f"Insert response {insert_response.data}")
return insert_response.data[0]