mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-21 02:11:35 +03:00
4112699db5
* ♻️ refactor backend main routes * 🗃️ new user_id uuid column in users table * 🗃️ new chats table * ✨ new chat endpoints * ✨ change chat routes post to handle undef chat_id * ♻️ extract components from chat page * ✨ add chatId to useQuestion * ✨ new ChatsList * ✨ new optional dynamic route chat/{chat_id} * 🩹 add setQuestion to speach utils * feat: self supplied key (#286) * feat(brain): increased size if api key and more * fix(key): not displayed * feat(apikey): now password input * fix(twitter): handle wrong * feat(chat): basic source documents support (#289) * ♻️ refactor backend main routes * 🗃️ new user_id uuid column in users table * 🗃️ new chats table * ✨ new chat endpoints * ✨ change chat routes post to handle undef chat_id * ♻️ extract components from chat page * ✨ add chatId to useQuestion * ✨ new ChatsList * ✨ new optional dynamic route chat/{chat_id} * 🩹 add setQuestion to speach utils * 🎨 separate creation and update endpoints for chat * 🩹 add feat(chat): basic source documents support * ✨ add chatName upon creation and for chats list * 💄 improve chatsList style * User chat history and multiple chats (#290) * ♻️ refactor backend main routes * 🗃️ new user_id uuid column in users table * 🗃️ new chats table * ✨ new chat endpoints * ✨ change chat routes post to handle undef chat_id * ♻️ extract components from chat page * ✨ add chatId to useQuestion * ✨ new ChatsList * ✨ new optional dynamic route chat/{chat_id} * refactor(chat): use layout to avoid refetching all chats on every chat * refactor(chat): useChats hook instead of useQuestion * fix(chat): fix errors * refactor(chat): better folder structure * feat: self supplied key (#286) * feat(brain): increased size if api key and more * fix(key): not displayed * feat(apikey): now password input * fix(twitter): handle wrong * feat(chat): basic source documents support (#289) * style(chat): better looking sidebar * resume merge * fix(backend): add os and logger imports * small fixes * chore(chat): remove empty interface * chore(chat): use const * fix(chat): merge errors * fix(chat): remove useSpeech args * chore(chat): remove unused args * fix(chat): remove duplicate components --------- Co-authored-by: gozineb <zinebe@theodo.fr> Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com> Co-authored-by: Stan Girard <girard.stanislas@gmail.com> Co-authored-by: xleven <xleven@outlook.com> * fix and refactor errors * fix(fresh): installation issues * chore(conflict): merged old code * fix(multi-chat): use update endpoint * feat(embeddings): now using users api key --------- Co-authored-by: Matt <77928207+mattzcarey@users.noreply.github.com> Co-authored-by: Stan Girard <girard.stanislas@gmail.com> Co-authored-by: xleven <xleven@outlook.com> Co-authored-by: Aditya Nandan <61308761+iMADi-ARCH@users.noreply.github.com> Co-authored-by: iMADi-ARCH <nandanaditya985@gmail.com> Co-authored-by: Mamadou DICKO <mamadoudicko100@gmail.com>
57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
import os
|
|
|
|
from fastapi import Depends, FastAPI, UploadFile
|
|
from models.users import User
|
|
from parsers.audio import process_audio
|
|
from parsers.common import file_already_exists
|
|
from parsers.csv import process_csv
|
|
from parsers.docx import process_docx
|
|
from parsers.epub import process_epub
|
|
from parsers.html import process_html
|
|
from parsers.markdown import process_markdown
|
|
from parsers.notebook import process_ipnyb
|
|
from parsers.odt import process_odt
|
|
from parsers.pdf import process_pdf
|
|
from parsers.powerpoint import process_powerpoint
|
|
from parsers.txt import process_txt
|
|
|
|
from supabase import Client
|
|
|
|
file_processors = {
|
|
".txt": process_txt,
|
|
".csv": process_csv,
|
|
".md": process_markdown,
|
|
".markdown": process_markdown,
|
|
".m4a": process_audio,
|
|
".mp3": process_audio,
|
|
".webm": process_audio,
|
|
".mp4": process_audio,
|
|
".mpga": process_audio,
|
|
".wav": process_audio,
|
|
".mpeg": process_audio,
|
|
".pdf": process_pdf,
|
|
".html": process_html,
|
|
".pptx": process_powerpoint,
|
|
".docx": process_docx,
|
|
".odt": process_odt,
|
|
".epub": process_epub,
|
|
".ipynb": process_ipnyb,
|
|
}
|
|
|
|
|
|
|
|
|
|
async def filter_file(file: UploadFile, enable_summarization: bool, supabase_client: Client, user: User, openai_api_key):
|
|
if await file_already_exists(supabase_client, file, user):
|
|
return {"message": f"🤔 {file.filename} already exists.", "type": "warning"}
|
|
elif file.file._file.tell() < 1:
|
|
return {"message": f"❌ {file.filename} is empty.", "type": "error"}
|
|
else:
|
|
file_extension = os.path.splitext(file.filename)[-1].lower() # Convert file extension to lowercase
|
|
if file_extension in file_processors:
|
|
await file_processors[file_extension](file, enable_summarization, user ,openai_api_key )
|
|
return {"message": f"✅ {file.filename} has been uploaded.", "type": "success"}
|
|
else:
|
|
return {"message": f"❌ {file.filename} is not supported.", "type": "error"}
|
|
|