Skip to content

refactor(api): Unify chat endpoint and process file uploads concurrently#288

Open
vatsaljain568 wants to merge 6 commits intojenkinsci:mainfrom
vatsaljain568:refactor/consolidate-chat-endpoint
Open

refactor(api): Unify chat endpoint and process file uploads concurrently#288
vatsaljain568 wants to merge 6 commits intojenkinsci:mainfrom
vatsaljain568:refactor/consolidate-chat-endpoint

Conversation

@vatsaljain568
Copy link
Contributor

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

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

Signed-off-by: Vatsal Jain <jain.vatsal2006@gmail.com>
@vatsaljain568 vatsaljain568 requested a review from a team as a code owner March 15, 2026 20:50
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>
@berviantoleo
Copy link
Contributor

Next time please test it properly before submitting PR.

UI/frontend is required for this kind of changes.

Copy link
Contributor

@berviantoleo berviantoleo left a comment

Choose a reason for hiding this comment

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

Breaking frontend

@vatsaljain568
Copy link
Contributor Author

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>
@vatsaljain568
Copy link
Contributor Author

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 (fetchChatbotReply for text and fetchChatbotReplyWithFiles for files) into one single function called sendMessage.
I changed this new function to always wrap the message data (whether it's just text, just files, or both) into a FormData object. This is the format the new backend endpoint expects for all messages.

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 sendMessage function every time the user sends a message.

3. Updated the Tests (frontend/src/tests/)

To ensure the fix was correct and to maintain code quality, updated the project's test files.
Removed the old tests that were checking the deleted functions and wrote new ones to specifically verify that the new sendMessage function works as expected for all cases (text, files, errors, etc.).

@berviantoleo berviantoleo added the major-rfe For changelog: Major enhancement. Will be highlighted on the top label Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

major-rfe For changelog: Major enhancement. Will be highlighted on the top

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants