Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 84abf0f

Browse files
committed
FIX: cancel functionality regressed
The cancel messaging was not floating correctly to the HTTP call
1 parent d83248c commit 84abf0f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/ai_bot/playground.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ def reply_to(post, custom_instructions: nil, &blk)
461461
if stream_reply && !Discourse.redis.get(redis_stream_key)
462462
cancel&.call
463463
reply_post.update!(raw: reply, cooked: PrettyText.cook(reply))
464+
break
464465
end
465466

466467
if post_streamer

lib/completions/endpoints/base.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,20 @@ def perform_completion!(
139139

140140
begin
141141
cancelled = false
142-
cancel = -> { cancelled = true }
143-
if cancelled
142+
cancel = -> do
143+
cancelled = true
144144
http.finish
145-
break
146145
end
147146

147+
break if cancelled
148+
148149
response.read_body do |chunk|
150+
break if cancelled
151+
149152
response_raw << chunk
153+
150154
decode_chunk(chunk).each do |partial|
155+
break if cancelled
151156
partials_raw << partial.to_s
152157
response_data << partial if partial.is_a?(String)
153158
partials = [partial]

0 commit comments

Comments
 (0)