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

Commit 65718f6

Browse files
authored
FIX: eat all leading spaces llms provide when they stream them (#1280)
* FIX: eat all leading spaces llms provide when they stream them * improve so we don't stop replying...
1 parent 2060426 commit 65718f6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/ai_bot/chat_streamer.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def initialize(message:, channel:, guardian:, thread_id:, in_reply_to_id:, force
3939

4040
def <<(partial)
4141
return if partial.to_s.empty?
42+
# we throw away leading spaces prior to message creation for now
43+
# by design
44+
return if partial.to_s.blank? && !@reply
4245

4346
if @client_id
4447
ChatSDK::Channel.stop_reply(

spec/lib/modules/ai_bot/playground_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@
354354
)
355355

356356
prompts = nil
357-
DiscourseAi::Completions::Llm.with_prepared_responses(["world"]) do |_, _, _prompts|
357+
DiscourseAi::Completions::Llm.with_prepared_responses([[" ", "world"]]) do |_, _, _prompts|
358358
message =
359359
ChatSDK::Message.create(
360360
channel_id: channel.id,
@@ -386,6 +386,9 @@
386386
TEXT
387387

388388
expect(content.strip).to eq(expected)
389+
390+
reply = Chat::Message.order(:id).last
391+
expect(reply.message).to eq("world")
389392
end
390393

391394
it "should reply to a mention if properly enabled" do

0 commit comments

Comments
 (0)