Add file upload support for chat sessions (#19)#61
Conversation
- Add file_service.py for processing uploaded files (text extraction, validation)
- Support 30+ file types including logs, code files, configs, and images
- Add multipart upload endpoint POST /sessions/{id}/message/upload
- Add GET /files/supported-extensions endpoint
- Update frontend with attach button, file preview chips, and drag-drop ready UI
- Display image thumbnails and file icons in chat messages
- Add file size validation (10MB limit) and extension checks
- Include unit tests for file service and upload routes
|
Also, a few checks are failing. Take a note! |
- Add python-multipart dependency for form data support - Use FileType Enum instead of string for type field (schemas.py) - Add proper model_validator for message/files validation (schemas.py) - Use XML-style tags for robust file context formatting (file_service.py) - Handle hidden files (.env, .gitignore, etc.) as text files - Add 'raise ... from e' pattern for exception chaining (chatbot.py) - Close uploaded files in finally block (chatbot.py) - Remove trailing whitespace and fix line length issues - Remove unused imports (Optional, pytest, TestClient) - Add tests for file size limit enforcement - Add tests for text truncation - Add tests for hidden files support - Add tests for file input trigger callback - Add whitespace-only negative case test - Use data-testid instead of emoji for file icons - Add missing mocks in Chatbot.test.tsx (fetchSupportedExtensions, etc.)
CI Failures FixedBackend Tests Failure
Resolution: Added Frontend Tests Failure
Resolution: Added missing mocks in jest.mock("../api/chatbot", () => ({
fetchChatbotReply: jest.fn()...,
fetchChatbotReplyWithFiles: jest.fn()...,
fetchSupportedExtensions: jest.fn().mockResolvedValue({...}),
validateFile: jest.fn().mockReturnValue({ isValid: true }),
fileToAttachment: jest.fn()...,
// ... other mocks
}));Pylint FailuresFixed all pylint issues:
|
…orrect data - Added mock_get_chatbot_reply.assert_called_once() assertions - Verify filename and content are correctly passed to service - Check multiple files are all processed correctly - Verify truncation logic works by checking content length
berviantoleo
left a comment
There was a problem hiding this comment.
Please see my comments. Some of them are required changes to strengthen the validation.
- Add python-magic for MIME type detection from content - Implement detect_mime_type_from_content() with fallback signatures - Add validate_file_content_type() to verify content matches extension - Block executables disguised as text files - Reject images with mismatched content/extension - Add comprehensive unit tests for new validation functions
|
Please have a look at the failed CIs |
…matting - Prioritize our magic byte signatures over python-magic for images - This ensures consistent behavior across different environments - Fix pylint unused-argument warning in test_file_upload.py - Fix broad-exception-caught by catching specific exceptions - Run prettier to fix frontend formatting issues - Update test for unknown content detection
d8bf116 to
d163334
Compare
|
Hey @berviantoleo, thanks for the review! We’ve been hitting some stubborn CI fails—mostly due to PyTorch and CUDA version conflicts on the latest Python. Our plan is to relax the strict version pins and let pip resolve the right dependencies, following PyTorch’s official guidance. If you’re good with this approach, we’ll go ahead and update the requirements accordingly. Let us know your thoughts! |
Good to go. However, @GunaPalanivel, please focusing to fix 3.12 and 3.13. I'm just experimenting with 3.14, so you can ignore the install dependencies error at the moment. |
|
@berviantoleo Done. |
88a97e8 to
d163334
Compare
Summary
Adds the ability for users to attach files when sending messages to the chatbot, giving the LLM richer context for troubleshooting Jenkins issues.
Changes
Backend (Python/FastAPI)
file_service.pymodule for file processing and validationPOST /sessions/{session_id}/message/uploadGET /files/supported-extensionsendpoint for frontend validationchat_service.pyto incorporate file content into LLM promptsFileAttachment,ChatRequestWithFiles,SupportedExtensionsResponseFrontend (React/TypeScript)
Supported File Types
.txt,.log,.md.py,.js,.ts,.tsx,.java,.groovy,.sh.json,.xml,.yaml,.yml,.properties,.tomlJenkinsfile,.groovy.png,.jpg,.jpeg,.gif,.webp,.bmpLimits
Testing
test_file_service.py)test_file_upload.py)How to Test
Closes #19