Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ en:

ai_bot_enabled: "Enable the AI Bot module."
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"
ai_bot_automatic_topic_title: "Automatically set the topic titles based on post contents."
ai_bot_allowed_groups: "When the GPT Bot has access to the PM, it will reply to members of these groups."
ai_bot_debugging_allowed_groups: "Allow these groups to see a debug button on posts which displays the raw AI request and response"
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."
Expand Down
2 changes: 2 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ discourse_ai:
ai_bot_enable_chat_warning:
default: false
client: true
ai_bot_automatic_topic_title:
default: true
ai_bot_debugging_allowed_groups:
type: group_list
list_type: compact
Expand Down
12 changes: 9 additions & 3 deletions lib/ai_bot/playground.rb
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,7 @@ def reply_to(post)
reply_post
ensure
publish_final_update(reply_post) if stream_reply
if reply_post && post.post_number == 1 && post.topic.private_message?
title_playground(reply_post)
end
title_playground(reply_post) if reply_post && can_automatically_update_title?(post)
end

def available_bot_usernames
Expand All @@ -503,6 +501,14 @@ def available_bot_user_ids

private

def can_automatically_update_title?(post)
return false if !SiteSetting.ai_bot_automatic_topic_title
return false if !post.topic.private_message?
return false if post.post_number != 1

true
end

def available_bot_users
@available_bots ||=
User.joins("INNER JOIN llm_models llm ON llm.user_id = users.id").where(active: true)
Expand Down
64 changes: 64 additions & 0 deletions spec/lib/modules/ai_bot/playground_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,70 @@
expect(custom_prompt.last.last).to eq(bot_user.username)
end

context "with title_playground" do
let(:playground) { DiscourseAi::AiBot::Playground.new(bot) }

before { allow(playground).to receive(:title_playground) }

context "when the ai_bot_automatic_topic_title config is disabled" do
before { SiteSetting.ai_bot_automatic_topic_title = false }

it "does not update the title" do
response = "This is a suggested title"

DiscourseAi::Completions::Llm.with_prepared_responses([response]) do
playground.reply_to(first_post)
end

expect(playground).not_to have_received(:title_playground)
end
end

context "when the message in the topic is not the private message" do
before { SiteSetting.ai_bot_automatic_topic_title = true }

it "does not update the title" do
allow(first_post.topic).to receive(:private_message?).and_return(false)

response = "This is a suggested title"

DiscourseAi::Completions::Llm.with_prepared_responses([response]) do
playground.reply_to(first_post)
end

expect(playground).not_to have_received(:title_playground)
end
end

context "when the post is not the first one in the topic" do
before { SiteSetting.ai_bot_automatic_topic_title = true }

it "does not update the title" do
response = "This is a suggested title"

DiscourseAi::Completions::Llm.with_prepared_responses([response]) do
playground.reply_to(second_post)
end

expect(playground).not_to have_received(:title_playground)
end
end

context "when the AI bot can automatically update the title" do
before { SiteSetting.ai_bot_automatic_topic_title = true }

it "updates the title using bot suggestions" do
response = "This is a suggested title"

DiscourseAi::Completions::Llm.with_prepared_responses([response]) do
playground.reply_to(first_post)
end

expect(playground).to have_received(:title_playground)
end
end
end

context "with Dall E bot" do
before { SiteSetting.ai_openai_api_key = "123" }

Expand Down