Proposal Generation
The proposal_generation_bp Blueprint in this Flask module manages the process of generating proposals based on user or AI-driven inputs, uploading proposal documents, and handling associated email notifications. Here’s a detailed breakdown of its functionality:
Blueprint Overview:
- Blueprint Name:
proposal_generation - Purpose: Handles all operations related to generating proposals from various inputs, including handling file uploads and integration with AI services for text processing and summarization.
Key Functions and Endpoints:
/proposal-generation
- Method:
POST - Functionality: This endpoint is used to generate a proposal based on a provided document URL. It processes the document to extract text, generates a proposal using AI, and uploads the resulting document, returning a download URL for the generated proposal.
- Steps:
- Validate user authentication.
- Download the document from the provided URL and extract text.
- Depending on the user’s subscription tier, generate either a short or long proposal.
- Create a Word document from the generated proposal text.
- Send an email with the document attached.
- Upload the document to Firebase and update the database with the URL.
- Clean up any temporary files.
/proposal-generation-find
- Method:
POST - Functionality: Generates a proposal based on existing contract details stored in the database. This can involve summarizing multiple documents and integrating various information to form a comprehensive proposal.
- Steps:
- Authenticate the user and retrieve their supplier details.
- Aggregate text from multiple documents or use the contract’s detailed description.
- Generate a proposal using AI based on the aggregated text.
- Handle document creation, emailing, and cleanup as in the previous endpoint.
Supporting Functions:
- File Handling: Functions such as
save_file_and_extract_texthandle the downloading and text extraction from documents, preparing them for AI processing. - AI Integration: Utilizes functions from
openai_functionsto generate proposals or summarize texts, adapting the response based on the user’s subscription tier. - Email Communication: Uses
email_helperfunctions to send formatted emails with attachments, facilitating professional communication with users. - Document Management: Involves creating formatted Word documents and managing uploads to Firebase storage.
- User and Supplier Management: Checks and updates related to the user’s and supplier’s status in the database, such as updating proposal generation counts and handling tier checks.
Error Handling:
- Comprehensive error handling across endpoints ensures that any issues during file handling, AI processing, or network communication are gracefully managed and reported to the user.
Usage:
- This blueprint is crucial for automating the proposal generation process in scenarios where quick, reliable, and contextually aware proposals are needed, enhancing the platform’s functionality for users engaging in contractual negotiations or submissions.