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

Commit 27356e3

Browse files
committed
FEATURE: Add a new setting to disable the automatic topic title feature of the AI bot
1 parent 94010a5 commit 27356e3

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +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?
490+
if reply_post && can_automatically_update_title?(post)
491491
title_playground(reply_post)
492492
end
493493
end
@@ -503,6 +503,14 @@ def available_bot_user_ids
503503

504504
private
505505

506+
def can_automatically_update_title?(post)
507+
return false if !SiteSetting.ai_bot_automatic_topic_title
508+
return false if !post.topic.private_message?
509+
return false if post.post_number != 1
510+
511+
true
512+
end
513+
506514
def available_bot_users
507515
@available_bots ||=
508516
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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,72 @@
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 do
812+
allow(playground).to receive(:title_playground)
813+
end
814+
815+
context "when the ai_bot_automatic_topic_title config is disabled" do
816+
before { SiteSetting.ai_bot_automatic_topic_title = false }
817+
818+
it "does not update the title" do
819+
response = "This is a suggested title"
820+
821+
DiscourseAi::Completions::Llm.with_prepared_responses([response]) do
822+
playground.reply_to(first_post)
823+
end
824+
825+
expect(playground).not_to have_received(:title_playground)
826+
end
827+
end
828+
829+
context "when the message in the topic is not the private message" do
830+
before { SiteSetting.ai_bot_automatic_topic_title = true }
831+
832+
it "does not update the title" do
833+
allow(first_post.topic).to receive(:private_message?).and_return(false)
834+
835+
response = "This is a suggested title"
836+
837+
DiscourseAi::Completions::Llm.with_prepared_responses([response]) do
838+
playground.reply_to(first_post)
839+
end
840+
841+
expect(playground).not_to have_received(:title_playground)
842+
end
843+
end
844+
845+
context "when the post is not the first one in the topic" do
846+
before { SiteSetting.ai_bot_automatic_topic_title = true }
847+
848+
it "does not update the title" do
849+
response = "This is a suggested title"
850+
851+
DiscourseAi::Completions::Llm.with_prepared_responses([response]) do
852+
playground.reply_to(second_post)
853+
end
854+
855+
expect(playground).not_to have_received(:title_playground)
856+
end
857+
end
858+
859+
context "when the AI bot can automatically update the title" do
860+
before { SiteSetting.ai_bot_automatic_topic_title = true }
861+
862+
it "updates the title using bot suggestions" do
863+
response = "This is a suggested title"
864+
865+
DiscourseAi::Completions::Llm.with_prepared_responses([response]) do
866+
playground.reply_to(first_post)
867+
end
868+
869+
expect(playground).to have_received(:title_playground)
870+
end
871+
end
872+
end
873+
808874
context "with Dall E bot" do
809875
before { SiteSetting.ai_openai_api_key = "123" }
810876

0 commit comments

Comments
 (0)