From 0f34ce999fcd98a95b580ed8cdbba53bda6bcb3b Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 15 Apr 2025 17:13:20 +1000 Subject: [PATCH] FIX: omit thinking tokens from chat (#1264) * FIX: omit thinking tokens from chat Thinking tokens cause a lot of confusion in chat, get rid of them * also catch partial tool just in case --- lib/ai_bot/playground.rb | 4 ++-- spec/lib/modules/ai_bot/playground_spec.rb | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/ai_bot/playground.rb b/lib/ai_bot/playground.rb index eb1f6272..bc467ee9 100644 --- a/lib/ai_bot/playground.rb +++ b/lib/ai_bot/playground.rb @@ -335,9 +335,9 @@ module DiscourseAi in_reply_to_id = channel.direct_message_channel? ? message.id : nil new_prompts = - bot.reply(context) do |partial, cancel, placeholder| + bot.reply(context) do |partial, cancel, placeholder, type| # no support for tools or thinking by design - next if !partial.is_a?(String) + next if type == :thinking || type == :tool_details || type == :partial_tool if !reply # just eat all leading spaces we can not create the message next if partial.blank? diff --git a/spec/lib/modules/ai_bot/playground_spec.rb b/spec/lib/modules/ai_bot/playground_spec.rb index 0159579a..750d1ea9 100644 --- a/spec/lib/modules/ai_bot/playground_spec.rb +++ b/spec/lib/modules/ai_bot/playground_spec.rb @@ -397,6 +397,13 @@ RSpec.describe DiscourseAi::AiBot::Playground do guardian: guardian, ) + thinking_partial = + DiscourseAi::Completions::Thinking.new( + message: "I should say hello", + signature: "thinking-signature-123", + partial: true, + ) + thinking = DiscourseAi::Completions::Thinking.new( message: "I should say hello", @@ -404,7 +411,7 @@ RSpec.describe DiscourseAi::AiBot::Playground do partial: false, ) DiscourseAi::Completions::Llm.with_prepared_responses( - [[thinking, thinking, "wo", "rld", thinking]], + [[thinking_partial, thinking, "wo", "rld"]], ) do |_, _, _prompts| ChatSDK::Message.create( channel_id: channel.id,