FEATURE: Adjustments to gist summaries (#988)
- makes visible to everyone by default - backfills gists before full summaries - adds configurable max age setting to backfill job
This commit is contained in:
parent
50ad5415ff
commit
0ac18d157b
|
@ -12,22 +12,26 @@ module ::Jobs
|
||||||
|
|
||||||
system_user = Discourse.system_user
|
system_user = Discourse.system_user
|
||||||
|
|
||||||
|
if SiteSetting.ai_summary_gists_enabled
|
||||||
|
gist_t = AiSummary.summary_types[:gist]
|
||||||
|
backfill_candidates(gist_t)
|
||||||
|
.limit(current_budget(gist_t))
|
||||||
|
.each do |topic|
|
||||||
|
DiscourseAi::Summarization.topic_gist(topic).force_summarize(system_user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
complete_t = AiSummary.summary_types[:complete]
|
complete_t = AiSummary.summary_types[:complete]
|
||||||
backfill_candidates(complete_t)
|
backfill_candidates(complete_t)
|
||||||
.limit(current_budget(complete_t))
|
.limit(current_budget(complete_t))
|
||||||
.each do |topic|
|
.each do |topic|
|
||||||
DiscourseAi::Summarization.topic_summary(topic).force_summarize(system_user)
|
DiscourseAi::Summarization.topic_summary(topic).force_summarize(system_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
return unless SiteSetting.ai_summary_gists_enabled
|
|
||||||
|
|
||||||
gist_t = AiSummary.summary_types[:gist]
|
|
||||||
backfill_candidates(gist_t)
|
|
||||||
.limit(current_budget(gist_t))
|
|
||||||
.each { |topic| DiscourseAi::Summarization.topic_gist(topic).force_summarize(system_user) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def backfill_candidates(summary_type)
|
def backfill_candidates(summary_type)
|
||||||
|
max_age_days = SiteSetting.ai_summary_backfill_topic_max_age_days
|
||||||
|
|
||||||
Topic
|
Topic
|
||||||
.where("topics.word_count >= ?", SiteSetting.ai_summary_backfill_minimum_word_count)
|
.where("topics.word_count >= ?", SiteSetting.ai_summary_backfill_minimum_word_count)
|
||||||
.joins(<<~SQL)
|
.joins(<<~SQL)
|
||||||
|
@ -36,6 +40,7 @@ module ::Jobs
|
||||||
ais.target_type = 'Topic' AND
|
ais.target_type = 'Topic' AND
|
||||||
ais.summary_type = '#{summary_type}'
|
ais.summary_type = '#{summary_type}'
|
||||||
SQL
|
SQL
|
||||||
|
.where("topics.created_at > current_timestamp - INTERVAL '#{max_age_days.to_i} DAY'")
|
||||||
.where(
|
.where(
|
||||||
"ais.id IS NULL OR UPPER(ais.content_range) < topics.highest_post_number + 1",
|
"ais.id IS NULL OR UPPER(ais.content_range) < topics.highest_post_number + 1",
|
||||||
) # (1..1) gets stored ad (1..2).
|
) # (1..1) gets stored ad (1..2).
|
||||||
|
|
|
@ -228,17 +228,17 @@ discourse_ai:
|
||||||
ai_summary_gists_allowed_groups:
|
ai_summary_gists_allowed_groups:
|
||||||
type: group_list
|
type: group_list
|
||||||
list_type: compact
|
list_type: compact
|
||||||
default: ""
|
default: "0" #everyone
|
||||||
ai_summarization_strategy: # TODO(roman): Deprecated. Remove by Sept 2024
|
|
||||||
type: enum
|
|
||||||
default: ""
|
|
||||||
hidden: true
|
hidden: true
|
||||||
choices: "DiscourseAi::Configuration::LlmEnumerator.old_summarization_options + ['']"
|
|
||||||
ai_summarization_model_allowed_seeded_models:
|
ai_summarization_model_allowed_seeded_models:
|
||||||
default: ""
|
default: ""
|
||||||
hidden: true
|
hidden: true
|
||||||
type: list
|
type: list
|
||||||
list_type: compact
|
list_type: compact
|
||||||
|
ai_summary_backfill_topic_max_age_days:
|
||||||
|
default: 30
|
||||||
|
min: 1
|
||||||
|
max: 10000
|
||||||
ai_summary_backfill_maximum_topics_per_hour:
|
ai_summary_backfill_maximum_topics_per_hour:
|
||||||
default: 0
|
default: 0
|
||||||
min: 0
|
min: 0
|
||||||
|
|
|
@ -64,6 +64,13 @@ RSpec.describe Jobs::SummariesBackfill do
|
||||||
|
|
||||||
expect(subject.backfill_candidates(type).map(&:id)).to contain_exactly(topic_2.id, topic.id)
|
expect(subject.backfill_candidates(type).map(&:id)).to contain_exactly(topic_2.id, topic.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "respects max age setting" do
|
||||||
|
SiteSetting.ai_summary_backfill_topic_max_age_days = 1
|
||||||
|
topic.update!(created_at: 2.days.ago)
|
||||||
|
|
||||||
|
expect(subject.backfill_candidates(type)).to be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#execute" do
|
describe "#execute" do
|
||||||
|
@ -80,7 +87,7 @@ RSpec.describe Jobs::SummariesBackfill do
|
||||||
gist_2 = "Gist of topic"
|
gist_2 = "Gist of topic"
|
||||||
|
|
||||||
DiscourseAi::Completions::Llm.with_prepared_responses(
|
DiscourseAi::Completions::Llm.with_prepared_responses(
|
||||||
[summary_1, summary_2, gist_1, gist_2],
|
[gist_1, gist_2, summary_1, summary_2],
|
||||||
) { subject.execute({}) }
|
) { subject.execute({}) }
|
||||||
|
|
||||||
expect(AiSummary.complete.find_by(target: topic_2).summarized_text).to eq(summary_1)
|
expect(AiSummary.complete.find_by(target: topic_2).summarized_text).to eq(summary_1)
|
||||||
|
|
|
@ -47,6 +47,7 @@ RSpec.describe DiscourseAi::Summarization::EntryPoint do
|
||||||
|
|
||||||
describe "topic_list_item serializer's ai_summary" do
|
describe "topic_list_item serializer's ai_summary" do
|
||||||
context "when hot topic summarization is disabled" do
|
context "when hot topic summarization is disabled" do
|
||||||
|
before { SiteSetting.ai_summary_gists_enabled = false }
|
||||||
it "doesn't include summaries" do
|
it "doesn't include summaries" do
|
||||||
gist_topic = topic_query.list_hot.topics.find { |t| t.id == topic_ai_gist.target_id }
|
gist_topic = topic_query.list_hot.topics.find { |t| t.id == topic_ai_gist.target_id }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue