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
This commit is contained in:
Sam 2025-04-15 17:13:20 +10:00 committed by GitHub
parent 274a54a324
commit 0f34ce999f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View File

@ -335,9 +335,9 @@ module DiscourseAi
in_reply_to_id = channel.direct_message_channel? ? message.id : nil in_reply_to_id = channel.direct_message_channel? ? message.id : nil
new_prompts = 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 # 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 if !reply
# just eat all leading spaces we can not create the message # just eat all leading spaces we can not create the message
next if partial.blank? next if partial.blank?

View File

@ -397,6 +397,13 @@ RSpec.describe DiscourseAi::AiBot::Playground do
guardian: guardian, guardian: guardian,
) )
thinking_partial =
DiscourseAi::Completions::Thinking.new(
message: "I should say hello",
signature: "thinking-signature-123",
partial: true,
)
thinking = thinking =
DiscourseAi::Completions::Thinking.new( DiscourseAi::Completions::Thinking.new(
message: "I should say hello", message: "I should say hello",
@ -404,7 +411,7 @@ RSpec.describe DiscourseAi::AiBot::Playground do
partial: false, partial: false,
) )
DiscourseAi::Completions::Llm.with_prepared_responses( DiscourseAi::Completions::Llm.with_prepared_responses(
[[thinking, thinking, "wo", "rld", thinking]], [[thinking_partial, thinking, "wo", "rld"]],
) do |_, _, _prompts| ) do |_, _, _prompts|
ChatSDK::Message.create( ChatSDK::Message.create(
channel_id: channel.id, channel_id: channel.id,