Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extended-files #1427

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Toddyclipsgg
Copy link

@Toddyclipsgg Toddyclipsgg commented Mar 2, 2025

Detailed Summary of Document Processing Feature

The implemented feature introduces a robust system for processing documents and files in the application, with a special focus on PDF and DOCX files. Here is a detailed breakdown of the features:

Document Text Extraction

The core component is the implementation of text extractors for different types of documents:

  1. DOCX file processing:
  • Uses the JSZip library to decompress the contents of the DOCX file
  • Parses the internal XML document (word/document.xml) to extract the text
  • Uses regular expressions to identify and extract the contents of <w:t> tags
  • Reconstructs the text of the document while maintaining basic formatting
  1. PDF file processing:
  • Implements a simplified approach that does not rely on PDF.js workers
  • Parses the raw bytes of the PDF to find text strings
  • Looks for common patterns in PDFs such as text enclosed in parentheses
  • Identifies uncompressed blocks of text enclosed in /BT and /ET tags
  • Extracts TJ and Tj command strings that frequently contain text
  • Processes and cleans the extracted text, preserving line breaks line

File Handling in the Interface

The system also implements a complete interface for uploading and manipulating files:

  1. File Upload:
  • Support for multiple file types (.md, .docx, .pdf, .txt)
  • File selection interface with appropriate filters
  • Asynchronous processing of selected files
  • Validation of file types and maximum size (5MB)
  1. Document Preview:
  • Display of specific icons per file type
  • Formatted preview for PDF and DOCX documents with distinctive icons
  • Special handling for text documents with proper formatting
  • Informative toast notifications about files attached
  1. Manipulation via Drag & Drop and Clipboard:
  • Support for dragging and dropping files into the interface
  • Capture of pasted files from the clipboard
  • Security validation to prevent uploading of scripted files
  • Visual feedback during the upload process
  1. Integration with the Chat System:
  • Adding files to the conversation context
  • Processing of documents before sending the message
  • Extracting text for analysis by the language model
  • State management for attached files

The feature implements a complete flow from uploading to processing and displaying documents, with a focus on user experience and security, avoiding potential problems with malicious or very large files.

Resource created from request: #1412 @leex279

.join('\n\n');

const contentWithFilesInfo = textFilesInfo ? `${messageContent}\n\n${textFilesInfo}` : messageContent;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should change the order,

Here is some context from files for your reference\n\n---\n ${textFilesInfo}\n---\n${messageContent}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should change the order,

Here is some context from files for your reference\n\n---\n ${textFilesInfo}\n---\n${messageContent}

Can I reverse the order then?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.. the content at the end gets more emphasis, so the AI will know what to do with all the context, if we put that after the context

@thecodacus
Copy link
Collaborator

I just got chance to review the code. looks goof to me.. @leex279 if you can test the functionality and UI then we are good I believe

@leex279
Copy link
Collaborator

leex279 commented Mar 5, 2025

will test later today

@Toddyclipsgg
Copy link
Author

I just got chance to review the code. looks goof to me.. @leex279 if you can test the functionality and UI then we are good I believe

Thanks @thecodacus for reviewing the feature!

@leex279
Copy link
Collaborator

leex279 commented Mar 5, 2025

Findings

PDF-Files look not working properly. Either it gets an error (maybe to big) or it does not use the pdf content as instruction, instead building a pdf viewer :D
1. Not working at all Example: https://www.cmu.edu/swartz-center-for-entrepreneurship/assets/creating-an-effective-landing-page.pdf
image

2. Building wrong app:
Unbenanntes Dokument.pdf
image

3. Styling could be improved (margin between filebox and chat):
image

@Toddyclipsgg
Copy link
Author

Can you please test it for me now? @leex279

@Toddyclipsgg Toddyclipsgg force-pushed the extended-files branch 2 times, most recently from 2925271 to 2e6b0e0 Compare March 8, 2025 14:09
@Toddyclipsgg Toddyclipsgg requested a review from thecodacus March 8, 2025 14:14
@Toddyclipsgg Toddyclipsgg reopened this Mar 9, 2025
@Toddyclipsgg
Copy link
Author

@thecodacus I ended up deleting the commits of the feature by accident if you can see if I didn't do anything wrong when I recovered the commits please!

@leex279
Copy link
Collaborator

leex279 commented Mar 9, 2025

@thecodacus please take a look. I dont know :D ... let me know when I can test/review again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants