Skip to content

[FEATURE] Add stop generation button to cancel ongoing AI response (#364)#385

Open
adikulkarni006 wants to merge 8 commits into
imDarshanGK:mainfrom
adikulkarni006:feature/stop-generation
Open

[FEATURE] Add stop generation button to cancel ongoing AI response (#364)#385
adikulkarni006 wants to merge 8 commits into
imDarshanGK:mainfrom
adikulkarni006:feature/stop-generation

Conversation

@adikulkarni006

Copy link
Copy Markdown
Collaborator

Closes #364

🎯 Problem

When the AI is generating a long response (streaming), users have no way to stop it mid‑way. They must wait or refresh the page.

🚀 Solution Implemented

  • Backend – No changes (streaming API already supports AbortSignal).
  • Frontend
    • api.js: streamMessage now accepts an optional signal parameter and passes it to fetch.
    • App.jsx: added abortController and isStreaming state, a stopGeneration function, and passes both to ChatWindow.
    • ChatWindow.jsx: shows a red Stop button while streaming; clicking it calls stopGeneration and aborts the request.
    • After abort, the partial response remains and [Stopped by user] is appended.

🧪 Testing Performed

  • ✅ Start a long streaming response → Stop button appears.
  • ✅ Click Stop → generation stops immediately, partial message stays with [Stopped by user].
  • ✅ No errors in console; abort does not affect other requests.
  • ✅ Existing Send behaviour unchanged.

📁 Files Changed

File Change
frontend/src/utils/api.js Added signal parameter to streamMessage
frontend/src/App.jsx Added abort controller, isStreaming, stopGeneration
frontend/src/components/ChatWindow.jsx Added Stop button & props

🔥 Why Merge?

  • ✅ Improves UX – users can cancel long responses.
  • ✅ Clean, minimal implementation using standard AbortController.
  • ✅ No breaking changes – works with both streaming and non‑streaming modes.

Ready for review.

@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

@adikulkarni006 is attempting to deploy a commit to the Darshan's projects Team on Vercel.

A member of the Team first needs to authorize it.

@adikulkarni006 adikulkarni006 added the SSoC26 Part of Social Summer of Code 2026 label Jun 11, 2026
@adikulkarni006

Copy link
Copy Markdown
Collaborator Author

@imDarshanGK PR is ready, all checks green. Please merge when you get a chance. Thanks!

@imDarshanGK

Copy link
Copy Markdown
Owner

@adikulkarni006 resolve conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

SSoC26 Part of Social Summer of Code 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add "Stop generation" button to cancel ongoing AI response

2 participants