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

Commit aa097b7

Browse files
committed
FEATURE: Extend summary backfill to also generate gists
Updates default batch size to 0 and max to 10000
1 parent 9928261 commit aa097b7

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

app/jobs/scheduled/summaries_backfill.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ def execute(_args)
1414
limit_per_job = [SiteSetting.ai_summary_backfill_maximum_topics_per_hour, 12].max / 12
1515
budget = [current_budget, limit_per_job].min
1616

17+
system_user = Discourse.system_user
18+
1719
backfill_candidates
1820
.limit(budget)
1921
.each do |topic|
20-
DiscourseAi::Summarization.topic_summary(topic).force_summarize(Discourse.system_user)
22+
DiscourseAi::Summarization.topic_summary(topic).force_summarize(system_user)
23+
DiscourseAi::Summarization.topic_gist(topic).force_summarize(system_user)
2124
end
2225
end
2326

@@ -27,10 +30,12 @@ def backfill_candidates
2730
.joins(
2831
"LEFT OUTER JOIN ai_summaries ais ON topics.id = ais.target_id AND ais.target_type = 'Topic'",
2932
)
30-
.where(
31-
"ais.id IS NULL OR UPPER(ais.content_range) < topics.highest_post_number + 1",
32-
) # (1..1) gets stored ad (1..2).
33-
.order("ais.created_at DESC NULLS FIRST, topics.last_posted_at DESC")
33+
.group("topics.id")
34+
.having(<<~SQL)
35+
BOOL_OR(ais.id IS NULL) OR
36+
BOOL_OR(ais.created_at IS NOT NULL AND UPPER(ais.content_range) < topics.highest_post_number + 1)
37+
SQL
38+
.order("MAX(ais.created_at) DESC NULLS FIRST, topics.last_posted_at DESC")
3439
end
3540

3641
def current_budget

config/settings.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,9 @@ discourse_ai:
376376
type: list
377377
list_type: compact
378378
ai_summary_backfill_maximum_topics_per_hour:
379-
default: 10
379+
default: 0
380380
min: 0
381-
max: 1000
381+
max: 10000
382382
ai_summary_backfill_minimum_word_count:
383383
default: 200
384384
hidden: true

spec/jobs/scheduled/summaries_backfill_spec.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,18 @@
9090
Fabricate(:ai_summary, target: topic, created_at: 3.hours.ago, content_range: (1..1))
9191

9292
summary_1 = "Summary of topic_2"
93+
gist_1 = "Gist of topic_2"
9394
summary_2 = "Summary of topic"
95+
gist_2 = "Gist of topic"
9496

95-
DiscourseAi::Completions::Llm.with_prepared_responses([summary_1, summary_2]) do
96-
subject.execute({})
97-
end
97+
DiscourseAi::Completions::Llm.with_prepared_responses(
98+
[summary_1, gist_1, summary_2, gist_2],
99+
) { subject.execute({}) }
98100

99-
expect(AiSummary.find_by(target: topic_2).summarized_text).to eq(summary_1)
100-
expect(AiSummary.find_by(target: topic).summarized_text).to eq(summary_2)
101+
expect(AiSummary.complete.find_by(target: topic_2).summarized_text).to eq(summary_1)
102+
expect(AiSummary.gist.find_by(target: topic_2).summarized_text).to eq(gist_1)
103+
expect(AiSummary.complete.find_by(target: topic).summarized_text).to eq(summary_2)
104+
expect(AiSummary.gist.find_by(target: topic).summarized_text).to eq(gist_2)
101105
end
102106
end
103107
end

0 commit comments

Comments
 (0)