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

Commit 083a834

Browse files
committed
Replace setting with a configurable batch size
1 parent f1113ac commit 083a834

File tree

7 files changed

+17
-16
lines changed

7 files changed

+17
-16
lines changed

app/jobs/regular/hot_topics_gist_batch.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ class HotTopicsGistBatch < ::Jobs::Base
55
def execute(args)
66
return if !SiteSetting.discourse_ai_enabled
77
return if !SiteSetting.ai_summarization_enabled
8-
return if !SiteSetting.ai_summarize_hot_topics_list
8+
return if SiteSetting.ai_summarize_max_hot_topics_gists_per_batch.zero?
99

1010
Topic
1111
.joins("JOIN topic_hot_scores on topics.id = topic_hot_scores.topic_id")
1212
.order("topic_hot_scores.score DESC")
13-
.limit(100)
13+
.limit(SiteSetting.ai_summarize_max_hot_topics_gists_per_batch)
1414
.each do |topic|
1515
summarizer = DiscourseAi::Summarization.topic_gist(topic)
1616
gist = summarizer.existing_summary

assets/javascripts/discourse/connectors/topic-list-main-link-bottom/ai-topic-gist.gjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Component from "@glimmer/component";
2-
import icon from "discourse-common/helpers/d-icon";
32

43
export default class AiTopicGist extends Component {
54
static shouldRender(outletArgs, helper) {

config/locales/server.en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ en:
8484
ai_summarization_model: "Model to use for summarization."
8585
ai_custom_summarization_allowed_groups: "Groups allowed to use create new summaries."
8686
ai_pm_summarization_allowed_groups: "Groups allowed to create and view summaries in PMs."
87-
ai_summarize_hot_topics_list: "Display a brief summary for each topic in the hot topics list (if available)."
87+
ai_summarize_max_hot_topics_gists_per_batch: "After updating topics in the hot list, we'll generate brief summaries of the first N ones. (Disabled when 0)"
8888

8989
ai_bot_enabled: "Enable the AI Bot module."
9090
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"

config/settings.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,10 @@ discourse_ai:
376376
type: group_list
377377
list_type: compact
378378
default: "3|13" # 3: @staff, 13: @trust_level_3
379-
ai_summarize_hot_topics_list:
380-
client: true
381-
default: false
379+
ai_summarize_max_hot_topics_gists_per_batch:
380+
default: 0
381+
min: 0
382+
max: 1000
382383
ai_summarization_strategy: # TODO(roman): Deprecated. Remove by Sept 2024
383384
type: enum
384385
default: ""

lib/summarization/entry_point.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def inject_into(plugin)
1919

2020
plugin.register_modifier(:topic_query_create_list_topics) do |topics, options|
2121
if options[:filter] == :hot && SiteSetting.ai_summarization_enabled &&
22-
SiteSetting.ai_summarize_hot_topics_list
22+
SiteSetting.ai_summarize_max_hot_topics_gists_per_batch > 0
2323
topics.includes(:ai_summaries).where(
2424
"ai_summaries.id IS NULL OR ai_summaries.summary_type = ?",
2525
AiSummary.summary_types[:gist],
@@ -33,7 +33,8 @@ def inject_into(plugin)
3333
:topic_list_item,
3434
:ai_topic_gist,
3535
include_condition: -> do
36-
SiteSetting.ai_summarization_enabled && SiteSetting.ai_summarize_hot_topics_list
36+
SiteSetting.ai_summarization_enabled &&
37+
SiteSetting.ai_summarize_max_hot_topics_gists_per_batch > 0
3738
end,
3839
) { object.ai_summaries.to_a.first&.summarized_text }
3940

spec/jobs/regular/hot_topics_gist_batch.rb renamed to spec/jobs/regular/hot_topics_gist_batch_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
before do
99
assign_fake_provider_to(:ai_summarization_model)
1010
SiteSetting.ai_summarization_enabled = true
11-
SiteSetting.ai_summarize_hot_topics_list = true
11+
SiteSetting.ai_summarize_max_hot_topics_gists_per_batch = 100
1212
end
1313

1414
describe "#execute" do
15-
context "When there is a topic with a hot score" do
15+
context "when there is a topic with a hot score" do
1616
before { TopicHotScore.create!(topic_id: topic_1.id, score: 0.1) }
1717

1818
it "does nothing if the plugin is disabled" do
@@ -34,7 +34,7 @@
3434
end
3535

3636
it "does nothing if hot topics summarization is disabled" do
37-
SiteSetting.ai_summarize_hot_topics_list = false
37+
SiteSetting.ai_summarize_max_hot_topics_gists_per_batch = 0
3838

3939
subject.execute({})
4040

@@ -48,10 +48,10 @@
4848
DiscourseAi::Completions::Llm.with_prepared_responses([gist_result]) { subject.execute({}) }
4949

5050
gist = AiSummary.gist.find_by(target: topic_1)
51-
expect(gist.summarized_text).to eq("I'm a gist")
51+
expect(gist.summarized_text).to eq(gist_result)
5252
end
5353

54-
context "and we already generated a gist of it" do
54+
context "when we already generated a gist of it" do
5555
fab!(:ai_gist) do
5656
Fabricate(
5757
:topic_ai_gist,

spec/lib/modules/summarization/entry_point_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
describe "topic_query_create_list_topics modifier" do
2121
context "when hot topic summarization is enabled" do
22-
before { SiteSetting.ai_summarize_hot_topics_list = true }
22+
before { SiteSetting.ai_summarize_max_hot_topics_gists_per_batch = 100 }
2323

2424
it "preloads only gist summaries" do
2525
gist_topic = topic_query.list_hot.topics.find { |t| t.id == topic_ai_gist.target_id }
@@ -49,7 +49,7 @@
4949
end
5050

5151
context "when hot topics summarization is enabled" do
52-
before { SiteSetting.ai_summarize_hot_topics_list = true }
52+
before { SiteSetting.ai_summarize_max_hot_topics_gists_per_batch = 100 }
5353

5454
it "includes the summary" do
5555
gist_topic = topic_query.list_hot.topics.find { |t| t.id == topic_ai_gist.target_id }

0 commit comments

Comments
 (0)