mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-16 10:02:30 +03:00
e53bc6807d
* 🗃️ add new tables for multiple brains * 🗑️ remove date input from fetch_user_id_from_credentials * ✨ new /brain endpoints * ♻️ refactor backend utils by splitting it into files * 💡 comments for next actions to update /upload
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
from logger import get_logger
|
|
from models.chats import ChatMessage
|
|
from utils.common import CommonsDep
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
def create_chat(commons: CommonsDep, user_id, history, chat_name):
|
|
# 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": user_id,
|
|
"history": history, # Empty chat to start
|
|
"chat_name": chat_name
|
|
}
|
|
insert_response = commons['supabase'].table('chats').insert(new_chat).execute()
|
|
logger.info(f"Insert response {insert_response.data}")
|
|
|
|
return(insert_response)
|
|
|
|
def update_chat(commons: CommonsDep, chat_id, history):
|
|
commons['supabase'].table("chats").update(
|
|
{ "history": history}).match({"chat_id": chat_id}).execute()
|
|
logger.info(f"Chat {chat_id} updated")
|
|
|
|
|
|
def get_chat_name_from_first_question( chat_message: ChatMessage):
|
|
# Step 1: Get the summary of the first question
|
|
# first_question_summary = summarize_as_title(chat_message.question)
|
|
# Step 2: Process this summary to create a chat name by selecting the first three words
|
|
chat_name = ' '.join(chat_message.question.split()[:3])
|
|
|
|
return chat_name
|