diff --git a/lib/ai_bot/chat_streamer.rb b/lib/ai_bot/chat_streamer.rb index bd441e7c5..139a6c7ff 100644 --- a/lib/ai_bot/chat_streamer.rb +++ b/lib/ai_bot/chat_streamer.rb @@ -39,6 +39,9 @@ def initialize(message:, channel:, guardian:, thread_id:, in_reply_to_id:, force def <<(partial) return if partial.to_s.empty? + # we throw away leading spaces prior to message creation for now + # by design + return if partial.to_s.blank? && !@reply if @client_id ChatSDK::Channel.stop_reply( diff --git a/spec/lib/modules/ai_bot/playground_spec.rb b/spec/lib/modules/ai_bot/playground_spec.rb index 750d1ea90..be6703996 100644 --- a/spec/lib/modules/ai_bot/playground_spec.rb +++ b/spec/lib/modules/ai_bot/playground_spec.rb @@ -354,7 +354,7 @@ ) prompts = nil - DiscourseAi::Completions::Llm.with_prepared_responses(["world"]) do |_, _, _prompts| + DiscourseAi::Completions::Llm.with_prepared_responses([[" ", "world"]]) do |_, _, _prompts| message = ChatSDK::Message.create( channel_id: channel.id, @@ -386,6 +386,9 @@ TEXT expect(content.strip).to eq(expected) + + reply = Chat::Message.order(:id).last + expect(reply.message).to eq("world") end it "should reply to a mention if properly enabled" do