A platform for community discussion. Free, open, simple.
DEV: Exclude thinking in the final output for locale detection (#42920)
Natalie Taya14a124a0da6
diff --git a/plugins/discourse-ai/lib/translation/language_detector.rb b/plugins/discourse-ai/lib/translation/language_detector.rbindex a1cd100d58d..9e51d7ca94b 100644--- a/plugins/discourse-ai/lib/translation/language_detector.rb+++ b/plugins/discourse-ai/lib/translation/language_detector.rb@@ -48,8 +48,9 @@ module DiscourseAi)result = +""- bot.reply(context) do |partial|- next if partial.strip.blank?+ bot.reply(context) do |partial, _, type|+ next if type == :thinking || partial.strip.blank?+result << partialenddiff --git a/plugins/discourse-ai/spec/lib/translation/language_detector_spec.rb b/plugins/discourse-ai/spec/lib/translation/language_detector_spec.rbindex 98807bf93e9..03c6504110c 100644--- a/plugins/discourse-ai/spec/lib/translation/language_detector_spec.rb+++ b/plugins/discourse-ai/spec/lib/translation/language_detector_spec.rb@@ -70,6 +70,15 @@ describe DiscourseAi::Translation::LanguageDetector doexpect(locale_detector.detect).to eq("nl")end+ it "returns the language when the streamed response includes thinking" do+ thinking =+ DiscourseAi::Completions::Thinking.new(message: "Determining Dutch context", partial: false)++ DiscourseAi::Completions::Llm.with_prepared_responses([[thinking, "nl"]]) do+ expect(locale_detector.detect).to eq("nl")+ end+ end+it "returns the language when the streamed response has surrounding whitespace" dobot = instance_double(DiscourseAi::Agents::Bot)allow(DiscourseAi::Agents::Bot).to receive(:as).and_return(bot)