Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 1ae2eac

Browse files
committed
FEATURE: Add a new setting to disable the automatic topic title feature of the AI bot
Add a new setting with the default set to true to maintain backward compatibility with the current behavior. We can utilize this setting to prevent our Playground from automatically generating the title right after it finishes the reply_to method.
1 parent 94010a5 commit 1ae2eac

File tree

4 files changed

+76
-3
lines changed

4 files changed

+76
-3
lines changed

config/locales/server.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ en:
8787

8888
ai_bot_enabled: "Enable the AI Bot module."
8989
ai_bot_enable_chat_warning: "Display a warning when PM chat is initiated. Can be overriden by editing the translation string: discourse_ai.ai_bot.pm_warning"
90+
ai_bot_automatic_topic_title: "Automatically set the topic titles based on post contents."
9091
ai_bot_allowed_groups: "When the GPT Bot has access to the PM, it will reply to members of these groups."
9192
ai_bot_debugging_allowed_groups: "Allow these groups to see a debug button on posts which displays the raw AI request and response"
9293
ai_bot_public_sharing_allowed_groups: "Allow these groups to share AI personal messages with the public via a unique publicly available link. Note: if your site requires login, shares will also require login."

config/settings.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ discourse_ai:
393393
ai_bot_enable_chat_warning:
394394
default: false
395395
client: true
396+
ai_bot_automatic_topic_title:
397+
default: true
396398
ai_bot_debugging_allowed_groups:
397399
type: group_list
398400
list_type: compact

lib/ai_bot/playground.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,7 @@ def reply_to(post)
487487
reply_post
488488
ensure
489489
publish_final_update(reply_post) if stream_reply
490-
if reply_post && post.post_number == 1 && post.topic.private_message?
491-
title_playground(reply_post)
492-
end
490+
title_playground(reply_post) if reply_post && can_automatically_update_title?(post)
493491
end
494492

495493
def available_bot_usernames
@@ -503,6 +501,14 @@ def available_bot_user_ids
503501

504502
private
505503

504+
def can_automatically_update_title?(post)
505+
return false if !SiteSetting.ai_bot_automatic_topic_title
506+
return false if !post.topic.private_message?
507+
return false if post.post_number != 1
508+
509+
true
510+
end
511+
506512
def available_bot_users
507513
@available_bots ||=
508514
User.joins("INNER JOIN llm_models llm ON llm.user_id = users.id").where(active: true)

spec/lib/modules/ai_bot/playground_spec.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,70 @@
805805
expect(custom_prompt.last.last).to eq(bot_user.username)
806806
end
807807

808+
context "with title_playground" do
809+
let(:playground) { DiscourseAi::AiBot::Playground.new(bot) }
810+
811+
before { allow(playground).to receive(:title_playground) }
812+
813+
context "when the ai_bot_automatic_topic_title config is disabled" do
814+
before { SiteSetting.ai_bot_automatic_topic_title = false }
815+
816+
it "does not update the title" do
817+
response = "This is a suggested title"
818+
819+
DiscourseAi::Completions::Llm.with_prepared_responses([response]) do
820+
playground.reply_to(first_post)
821+
end
822+
823+
expect(playground).not_to have_received(:title_playground)
824+
end
825+
end
826+
827+
context "when the message in the topic is not the private message" do
828+
before { SiteSetting.ai_bot_automatic_topic_title = true }
829+
830+
it "does not update the title" do
831+
allow(first_post.topic).to receive(:private_message?).and_return(false)
832+
833+
response = "This is a suggested title"
834+
835+
DiscourseAi::Completions::Llm.with_prepared_responses([response]) do
836+
playground.reply_to(first_post)
837+
end
838+
839+
expect(playground).not_to have_received(:title_playground)
840+
end
841+
end
842+
843+
context "when the post is not the first one in the topic" do
844+
before { SiteSetting.ai_bot_automatic_topic_title = true }
845+
846+
it "does not update the title" do
847+
response = "This is a suggested title"
848+
849+
DiscourseAi::Completions::Llm.with_prepared_responses([response]) do
850+
playground.reply_to(second_post)
851+
end
852+
853+
expect(playground).not_to have_received(:title_playground)
854+
end
855+
end
856+
857+
context "when the AI bot can automatically update the title" do
858+
before { SiteSetting.ai_bot_automatic_topic_title = true }
859+
860+
it "updates the title using bot suggestions" do
861+
response = "This is a suggested title"
862+
863+
DiscourseAi::Completions::Llm.with_prepared_responses([response]) do
864+
playground.reply_to(first_post)
865+
end
866+
867+
expect(playground).to have_received(:title_playground)
868+
end
869+
end
870+
end
871+
808872
context "with Dall E bot" do
809873
before { SiteSetting.ai_openai_api_key = "123" }
810874

0 commit comments

Comments
 (0)