quivr/backend/repository/chat/create_chat.py
MaHDi 8af6d61e76
improve (importing): reorganization of the import structure (#964)
* reorganize import level

* add __init__, reorganize import from __init__

* reorganize import level

* reorganize import level

* fix circular import error by keep the import deep as "from models.settings"

* fix the relative import

* restor unwanted staged files

* add backend/venv and backend/.env to gitignore

* clean importing
2023-08-21 12:25:16 +02:00

33 lines
804 B
Python

from dataclasses import dataclass
from uuid import UUID
from logger import get_logger
from models import Chat, get_supabase_db
logger = get_logger(__name__)
@dataclass
class CreateChatProperties:
name: str
def __init__(self, name: str):
self.name = name
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 = {
"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]