mirror of
https://github.com/StanGirard/quivr.git
synced 2024-10-26 22:10:26 +03:00
fix: 🐛 crawler (#1735)
fixed # Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
This commit is contained in:
parent
10e94e5a91
commit
7ff081cf40
@ -58,6 +58,7 @@ def process_file_and_notify(
|
|||||||
brain_id,
|
brain_id,
|
||||||
notification_id=None,
|
notification_id=None,
|
||||||
):
|
):
|
||||||
|
try:
|
||||||
supabase_client = get_supabase_client()
|
supabase_client = get_supabase_client()
|
||||||
tmp_file_name = "tmp-file-" + file_name
|
tmp_file_name = "tmp-file-" + file_name
|
||||||
tmp_file_name = tmp_file_name.replace("/", "_")
|
tmp_file_name = tmp_file_name.replace("/", "_")
|
||||||
@ -101,6 +102,23 @@ def process_file_and_notify(
|
|||||||
update_brain_last_update_time(brain_id)
|
update_brain_last_update_time(brain_id)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
notification_message = {
|
||||||
|
"status": "error",
|
||||||
|
"message": "There was an error uploading the file. Please check the file and try again. If the issue persist, please open an issue on Github",
|
||||||
|
"name": file_instance.file.filename if file_instance.file else "",
|
||||||
|
}
|
||||||
|
update_notification_by_id(
|
||||||
|
notification_id,
|
||||||
|
NotificationUpdatableProperties(
|
||||||
|
status=NotificationsStatusEnum.Done,
|
||||||
|
message=str(notification_message),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@celery.task(name="process_crawl_and_notify")
|
@celery.task(name="process_crawl_and_notify")
|
||||||
|
@ -31,4 +31,4 @@ async def process_file(
|
|||||||
brain_id, doc_with_metadata.to_json(), file.file_sha1
|
brain_id, doc_with_metadata.to_json(), file.file_sha1
|
||||||
)
|
)
|
||||||
|
|
||||||
return "Hello World!"
|
return len(file.documents)
|
||||||
|
@ -81,12 +81,17 @@ async def filter_file(
|
|||||||
|
|
||||||
if file.file_extension in file_processors:
|
if file.file_extension in file_processors:
|
||||||
try:
|
try:
|
||||||
await file_processors[file.file_extension](
|
result = await file_processors[file.file_extension](
|
||||||
file=file,
|
file=file,
|
||||||
brain_id=brain_id,
|
brain_id=brain_id,
|
||||||
)
|
)
|
||||||
|
if result is None or result == 0:
|
||||||
return create_response(
|
return create_response(
|
||||||
f"✅ {using_file_name} has been uploaded to brain {brain.name}.", # pyright: ignore reportPrivateUsage=none
|
f"? {using_file_name} has been uploaded to brain. There might have been an error while reading it, please make sure the file is not illformed or just an image", # pyright: ignore reportPrivateUsage=none
|
||||||
|
"warning",
|
||||||
|
)
|
||||||
|
return create_response(
|
||||||
|
f"✅ {using_file_name} has been uploaded to brain {brain.name} in {result} chunks", # pyright: ignore reportPrivateUsage=none
|
||||||
"success",
|
"success",
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -15,6 +15,10 @@ from packages.files.file import convert_bytes, get_file_size
|
|||||||
from repository.knowledge.add_knowledge import add_knowledge
|
from repository.knowledge.add_knowledge import add_knowledge
|
||||||
from repository.files.upload_file import upload_file_storage
|
from repository.files.upload_file import upload_file_storage
|
||||||
from repository.notification.add_notification import add_notification
|
from repository.notification.add_notification import add_notification
|
||||||
|
from repository.notification.update_notification import update_notification_by_id
|
||||||
|
from models.databases.supabase.notifications import NotificationUpdatableProperties
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from routes.authorizations.brain_authorization import (
|
from routes.authorizations.brain_authorization import (
|
||||||
RoleEnum,
|
RoleEnum,
|
||||||
@ -73,6 +77,19 @@ async def upload_file(
|
|||||||
logger.info(f"File {file_in_storage} uploaded successfully")
|
logger.info(f"File {file_in_storage} uploaded successfully")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
notification_message = {
|
||||||
|
"status": "error",
|
||||||
|
"message": "There was an error uploading the file. Please check the file and try again. If the issue persist, please open an issue on Github",
|
||||||
|
"name": uploadFile.filename if uploadFile else "Last Upload File",
|
||||||
|
}
|
||||||
|
update_notification_by_id(
|
||||||
|
upload_notification.id,
|
||||||
|
NotificationUpdatableProperties(
|
||||||
|
status=NotificationsStatusEnum.Done,
|
||||||
|
message=str(notification_message),
|
||||||
|
),
|
||||||
|
)
|
||||||
if "The resource already exists" in str(e):
|
if "The resource already exists" in str(e):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=403,
|
status_code=403,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
CREATE OR REPLACE FUNCTION update_max_brains_theodo() RETURNS TRIGGER AS $$
|
CREATE OR REPLACE FUNCTION update_max_brains_theodo() RETURNS TRIGGER AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
userEmail TEXT;
|
userEmail TEXT;
|
||||||
allowedDomains TEXT[] := ARRAY['%@theodo.fr', '%@theodo.com', '%@theodo.co.uk', '%@bam.tech', '%@padok.fr', '%@sicara.com', '%@hokla.com', '%@sipios.com'];
|
allowedDomains TEXT[] := ARRAY['%@theodo.fr', '%@theodo.com', '%@theodo.co.uk', '%@bam.tech', '%@padok.fr', '%@aleios.com', '%@sicara.com', '%@hokla.com', '%@sipios.com'];
|
||||||
BEGIN
|
BEGIN
|
||||||
SELECT email INTO userEmail FROM auth.users WHERE id = NEW.user_id;
|
SELECT email INTO userEmail FROM auth.users WHERE id = NEW.user_id;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user