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

Commit 21a851d

Browse files
committed
FIX: eat all leading spaces llms provide when they stream them
1 parent 2060426 commit 21a851d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/ai_bot/chat_streamer.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def <<(partial)
5353
if @reply
5454
@queue << partial
5555
else
56-
create_reply(partial)
56+
# we throw away leading spaces prior to message creation for now
57+
# by design
58+
create_reply(partial) if partial.present?
5759
end
5860
end
5961

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)