-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "feat(celery): moved assistant summary to celery" (#2558)
Reverts #2557
- Loading branch information
1 parent
5583436
commit cd73412
Showing
4 changed files
with
113 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,13 @@ | |
|
||
from fastapi import UploadFile | ||
from logger import get_logger | ||
from modules.user.service.user_usage import UserUsage | ||
from modules.assistant.dto.inputs import InputAssistant | ||
from modules.assistant.ito.utils.pdf_generator import PDFGenerator, PDFModel | ||
from modules.chat.controller.chat.utils import update_user_usage | ||
from modules.contact_support.controller.settings import ContactsSettings | ||
from modules.upload.controller.upload_routes import upload_file | ||
from modules.user.entity.user_identity import UserIdentity | ||
from modules.user.service.user_usage import UserUsage | ||
from packages.emails.send_email import send_email | ||
from pydantic import BaseModel | ||
from unidecode import unidecode | ||
|
@@ -62,36 +62,31 @@ def increase_usage_user(self): | |
def calculate_pricing(self): | ||
return 20 | ||
|
||
def generate_pdf(self, filename: str, title: str, content: str): | ||
pdf_model = PDFModel(title=title, content=content) | ||
pdf = PDFGenerator(pdf_model) | ||
pdf.print_pdf() | ||
pdf.output(filename, "F") | ||
|
||
@abstractmethod | ||
async def process_assistant(self): | ||
pass | ||
|
||
|
||
async def uploadfile_to_file(uploadFile: UploadFile): | ||
# Transform the UploadFile object to a file object with same name and content | ||
tmp_file = NamedTemporaryFile(delete=False) | ||
tmp_file.write(uploadFile.file.read()) | ||
tmp_file.flush() # Make sure all data is written to disk | ||
return tmp_file | ||
|
||
|
||
class OutputHandler(BaseModel): | ||
async def send_output_by_email( | ||
self, | ||
filename: str, | ||
file: UploadFile, | ||
filename: str, | ||
task_name: str, | ||
custom_message: str, | ||
brain_id: str = None, | ||
user_email: str = None, | ||
): | ||
settings = ContactsSettings() | ||
file = await uploadfile_to_file(file) | ||
file = await self.uploadfile_to_file(file) | ||
domain_quivr = os.getenv("QUIVR_DOMAIN", "https://chat.quivr.app/") | ||
|
||
with open(file.name, "rb") as f: | ||
mail_from = settings.resend_contact_sales_from | ||
mail_to = user_email | ||
mail_to = self.current_user.email | ||
body = f""" | ||
<div style="text-align: center;"> | ||
<img src="https://quivr-cms.s3.eu-west-3.amazonaws.com/logo_quivr_white_7e3c72620f.png" alt="Quivr Logo" style="width: 100px; height: 100px; border-radius: 50%; margin: 0 auto; display: block;"> | ||
|
@@ -121,34 +116,20 @@ async def send_output_by_email( | |
"subject": "Quivr Ingestion Processed", | ||
"reply_to": "[email protected]", | ||
"html": body, | ||
"attachments": [ | ||
{ | ||
"filename": filename, | ||
"content": list(f.read()), | ||
"type": "application/pdf", | ||
} | ||
], | ||
"attachments": [{"filename": filename, "content": list(f.read())}], | ||
} | ||
logger.info(f"Sending email to {mail_to} with file {filename}") | ||
send_email(params) | ||
|
||
def generate_pdf(self, filename: str, title: str, content: str): | ||
pdf_model = PDFModel(title=title, content=content) | ||
pdf = PDFGenerator(pdf_model) | ||
pdf.print_pdf() | ||
pdf.output(filename, "F") | ||
async def uploadfile_to_file(self, uploadFile: UploadFile): | ||
# Transform the UploadFile object to a file object with same name and content | ||
tmp_file = NamedTemporaryFile(delete=False) | ||
tmp_file.write(uploadFile.file.read()) | ||
tmp_file.flush() # Make sure all data is written to disk | ||
return tmp_file | ||
|
||
async def create_and_upload_processed_file( | ||
self, | ||
processed_content: str, | ||
original_filename: str, | ||
file_description: str, | ||
content: str, | ||
task_name: str, | ||
custom_message: str, | ||
brain_id: str = None, | ||
email_activated: bool = False, | ||
current_user: UserIdentity = None, | ||
self, processed_content: str, original_filename: str, file_description: str | ||
) -> dict: | ||
"""Handles creation and uploading of the processed file.""" | ||
# remove any special characters from the filename that aren't http safe | ||
|
@@ -183,25 +164,29 @@ async def create_and_upload_processed_file( | |
headers={"content-type": "application/pdf"}, | ||
) | ||
|
||
logger.info(f"current_user: {current_user}") | ||
if email_activated: | ||
if self.input.outputs.email.activated: | ||
await self.send_output_by_email( | ||
new_filename, | ||
file_to_upload, | ||
new_filename, | ||
"Summary", | ||
f"{file_description} of {original_filename}", | ||
brain_id=brain_id, | ||
user_email=current_user["email"], | ||
brain_id=( | ||
self.input.outputs.brain.value | ||
if ( | ||
self.input.outputs.brain.activated | ||
and self.input.outputs.brain.value | ||
) | ||
else None | ||
), | ||
) | ||
|
||
# Reset to start of file before upload | ||
file_to_upload.file.seek(0) | ||
UserIdentity(**current_user) | ||
if brain_id: | ||
if self.input.outputs.brain.activated: | ||
await upload_file( | ||
uploadFile=file_to_upload, | ||
brain_id=brain_id, | ||
current_user=current_user, | ||
brain_id=self.input.outputs.brain.value, | ||
current_user=self.current_user, | ||
chat_id=None, | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.