refactor(api): Unify chat endpoint and process file uploads concurrently#288
refactor(api): Unify chat endpoint and process file uploads concurrently#288vatsaljain568 wants to merge 6 commits intojenkinsci:mainfrom
Conversation
Signed-off-by: Vatsal Jain <jain.vatsal2006@gmail.com>
Signed-off-by: Vatsal Jain <jain.vatsal2006@gmail.com>
Signed-off-by: Vatsal Jain <jain.vatsal2006@gmail.com>
Signed-off-by: Vatsal Jain <jain.vatsal2006@gmail.com>
|
Next time please test it properly before submitting PR. UI/frontend is required for this kind of changes. |
|
I apologize for the test failures and the broken frontend. I completely focused on testing the backend API and overlooked updating the UI to match the new endpoints. I will make sure to thoroughly test the full stack before submitting next time. I am spinning up the frontend right now to resolve the issue and will push the fix shortly. |
…oint Signed-off-by: Vatsal Jain <jain.vatsal2006@gmail.com>
Signed-off-by: Vatsal Jain <jain.vatsal2006@gmail.com>
|
To resolve the Frontend break , I made the frontend's code match the new backend structure. This involved three main areas: 1. Unified the API Functions ([frontend/src/api/chatbot.ts] Just like the backend, I consolidated the two separate frontend functions ( 2. Updated the UI Component ([frontend/src/components/Chatbot.tsx] Then went into the main Chatbot component, which handles the user input, updated its logic to stop deciding between the two old functions and instead just call the new, single 3. Updated the Tests (frontend/src/tests/) To ensure the fix was correct and to maintain code quality, updated the project's test files. |
This refactors the chat API by consolidating the two separate reply endpoints into a single, more robust endpoint. It also introduces concurrent file processing to improve performance.
Testing done
The changes were manually tested by running the FastAPI server locally and using an API client (curl) to simulate various user interactions with the new consolidated endpoint at POST /sessions/{session_id}/message
The following scenarios were verified:
1. Text-Only Message:
2. File-Only Upload:
Action: Sent a request with a single file and no message field.
Command: curl -X POST -F "files=@/path" http://127.0.0.1:8000/sessions/{session_id}/message
Result: Received a 200 OK response. The backend correctly used the default prompt ("Please analyze the attached file(s).") to process the file.
3. Multiple File Upload:
Action: Sent a request with multiple files simultaneously.
Command: curl -X POST -F "files=@/path" -F "files=@/path" http://127.0.0.1:8000/sessions/{session_id}/message
Result: Received a 200 OK response. The concurrent processing logic handled both files correctly.
4. Text and File Upload:
Action: Sent a request with both a message and a file.
Command: curl -X POST -F "message=What is in this file?" -F "files=@/path" http://127.0.0.1:8000/sessions/{session_id}/message
Result: Received a 200 OK response with a reply relevant to both the message and the file content.
5. Invalid Request (No Data):
Action: Sent a request with neither a message nor files.
Command: curl -X POST http://127.0.0.1:8000/sessions/{session_id}/message
Result: Correctly received a 422 Unprocessable Entity error with the detail message "Either a message or at least one file must be provided.".
After refactoring, the external behavior of the API remains consistent, while the underlying implementation is now cleaner, more performant, and easier to maintain.
Submitter checklist