Skip to content

A platform for community discussion. Free, open, simple.

FIX: Thinking could leak into topics in automation (#36239)

Samf5aac07f85bb
diff --git a/plugins/discourse-ai/lib/ai_bot/playground.rb b/plugins/discourse-ai/lib/ai_bot/playground.rb
index f759bfa623c..047db3fe1a0 100644
--- a/plugins/discourse-ai/lib/ai_bot/playground.rb
+++ b/plugins/discourse-ai/lib/ai_bot/playground.rb
@@ -492,7 +492,9 @@ module DiscourseAi
new_custom_prompts =
bot.reply(context) do |partial, placeholder, type|
- next if (partial.to_s == "" && placeholder.to_s != "" && context.skip_show_thinking)
+ if context.skip_show_thinking && %i[thinking partial_tool partial_invoke].include?(type)
+ next
+ end
next if type == :structured_output && !partial.finished?
if should_start_thinking?(partial:, context:, type:, started_thinking:, placeholder:)
diff --git a/plugins/discourse-ai/spec/lib/discourse_automation/llm_persona_triage_spec.rb b/plugins/discourse-ai/spec/lib/discourse_automation/llm_persona_triage_spec.rb
index b7f3ecddef4..b60b12073d9 100644
--- a/plugins/discourse-ai/spec/lib/discourse_automation/llm_persona_triage_spec.rb
+++ b/plugins/discourse-ai/spec/lib/discourse_automation/llm_persona_triage_spec.rb
@@ -97,6 +97,30 @@ describe DiscourseAi::Automation::LlmPersonaTriage do
expect(last_post.post_type).to eq(Post.types[:regular]) # Not a whisper
end
+ it "hides thinking output when the persona is configured to do so" do
+ post = Fabricate(:post, raw: "This is a test post that needs triage")
+
+ thinking =
+ DiscourseAi::Completions::Thinking.new(
+ message: "Internal chain-of-thought that should stay hidden",
+ partial: false,
+ )
+
+ DiscourseAi::Completions::Llm.with_prepared_responses(
+ [[thinking, "Here is the public reply"]],
+ ) do
+ automation.running_in_background!
+ automation.trigger!({ "post" => post })
+ end
+
+ topic = post.topic.reload
+ last_post = topic.posts.order(:post_number).last
+
+ expect(topic.posts.count).to eq(2)
+ expect(last_post.raw).to eq("Here is the public reply")
+ expect(last_post.raw).not_to include("Internal chain-of-thought")
+ end
+
it "can respond with a whisper when configured to do so" do
add_automation_field("whisper", true, type: "boolean")
post = Fabricate(:post, raw: "This is another test post for triage")
diff --git a/plugins/discourse-ai/spec/lib/modules/ai_bot/playground_spec.rb b/plugins/discourse-ai/spec/lib/modules/ai_bot/playground_spec.rb
index bc731025138..6b2c21b51cf 100644
--- a/plugins/discourse-ai/spec/lib/modules/ai_bot/playground_spec.rb
+++ b/plugins/discourse-ai/spec/lib/modules/ai_bot/playground_spec.rb
@@ -135,9 +135,7 @@ RSpec.describe DiscourseAi::AiBot::Playground do
upload = Upload.find(upload_id)
- expect(reply_post.raw).to match(
- /\A\*\*searching for things\*\*\s+!\[image\]\(#{Regexp.escape(upload.short_url)}\)\s*\z/,
- )
+ expect(reply_post.raw).to eq("![image](#{upload.short_url})")
end
it "can force usage of a tool" do
diff --git a/plugins/discourse-ai/spec/models/ai_api_request_stat_spec.rb b/plugins/discourse-ai/spec/models/ai_api_request_stat_spec.rb
index 54599373938..ad4a821e5f6 100644
--- a/plugins/discourse-ai/spec/models/ai_api_request_stat_spec.rb
+++ b/plugins/discourse-ai/spec/models/ai_api_request_stat_spec.rb
@@ -74,7 +74,7 @@ describe AiApiRequestStat do
)
# Recent data - should not be rolled up
- recent_time = 1.hour.ago
+ recent_time = Time.zone.now
_stat4 =
AiApiRequestStat.create!(
bucket_date: recent_time,