Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
# frozen_string_literal: true

module ::Jobs
class UpdateHotTopicGist < ::Jobs::Base
class FastTrackTopicGist < ::Jobs::Base
sidekiq_options retry: false

def execute(args)
return if !SiteSetting.discourse_ai_enabled
return if !SiteSetting.ai_summarization_enabled
return if SiteSetting.ai_summarize_max_hot_topics_gists_per_batch.zero?
return if SiteSetting.ai_summary_gists_enabled

topic = Topic.find_by(id: args[:topic_id])
return if topic.blank?

return if !TopicHotScore.where(topic: topic).exists?

summarizer = DiscourseAi::Summarization.topic_gist(topic)
gist = summarizer.existing_summary
return if gist.blank?
return if !gist.outdated
return if gist.present? && !gist.outdated

summarizer.force_summarize(Discourse.system_user)
end
Expand Down
22 changes: 0 additions & 22 deletions app/jobs/regular/hot_topics_gist_batch.rb

This file was deleted.

4 changes: 2 additions & 2 deletions config/locales/server.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ de:
ai_summarization_model: "Modell, das für die Zusammenfassung verwendet werden soll."
ai_custom_summarization_allowed_groups: "Gruppen, die neue Zusammenfassungen erstellen dürfen."
ai_pm_summarization_allowed_groups: "Gruppen können Zusammenfassungen in PMs erstellen und ansehen."
ai_summarize_max_hot_topics_gists_per_batch: "Nach der Aktualisierung der Themen in der angesagten Liste erstellen wir kurze Zusammenfassungen der ersten N Themen. (Deaktiviert, wenn 0)"
ai_summary_gists_enabled: "Nach der Aktualisierung der Themen in der angesagten Liste erstellen wir kurze Zusammenfassungen der ersten N Themen. (Deaktiviert, wenn 0)"
ai_hot_topic_gists_allowed_groups: "Gruppen, die die wichtigsten Themen in der Liste der aktuellen Themen sehen dürfen."
ai_summary_backfill_maximum_topics_per_hour: "Anzahl der Themenzusammenfassungen, die pro Stunde aufgefüllt werden müssen."
ai_bot_enabled: "Aktiviere das KI-Bot-Modul."
Expand Down Expand Up @@ -372,7 +372,7 @@ de:
endpoints:
not_configured: "%{display_name} (nicht konfiguriert)"
configuration_hint:
one: "Vergewissere dich, dass die Einstellung \"%{settings}\" konfiguriert wurde."
one: 'Vergewissere dich, dass die Einstellung "%{settings}" konfiguriert wurde.'
other: "Vergewissere dich, dass diese Einstellungen konfiguriert wurden: %{settings}"
delete_failed:
one: "Wir konnten dieses Modell nicht löschen, weil es von %{settings} verwendet wird. Aktualisiere die Einstellung und versuche es erneut."
Expand Down
2 changes: 1 addition & 1 deletion config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ en:
ai_summarization_model: "Model to use for summarization."
ai_custom_summarization_allowed_groups: "Groups allowed to use create new summaries."
ai_pm_summarization_allowed_groups: "Groups allowed to create and view summaries in PMs."
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)"
ai_summary_gists_enabled: "After updating topics in the hot list, we'll generate brief summaries of the first N ones. (Disabled when 0)"
ai_hot_topic_gists_allowed_groups: "Groups allowed to see gists in the hot topics list."
ai_summary_backfill_maximum_topics_per_hour: "Number of topic summaries to backfill per hour."

Expand Down
4 changes: 2 additions & 2 deletions config/locales/server.he.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ he:
ai_summarization_model: "מודל לשימוש לסיכום."
ai_custom_summarization_allowed_groups: "קבוצות שמורשות להשתמש ליצירת סיכומים חדשים."
ai_pm_summarization_allowed_groups: "קבוצות שמורשות ליצור ולצפות בתקצירים בהודעות פרטיות."
ai_summarize_max_hot_topics_gists_per_batch: "לאחר עדכון הנושאים ברשימה החמה, נייצר תקצירים של N הראשונים. (0 להשבתה)"
ai_summary_gists_enabled: "לאחר עדכון הנושאים ברשימה החמה, נייצר תקצירים של N הראשונים. (0 להשבתה)"
ai_hot_topic_gists_allowed_groups: "קבוצות שמורשות לראות gists ברשימת הנושאים החמים."
ai_summary_backfill_maximum_topics_per_hour: "מספר תקצירי הנושאים למילוי חוזר בשעה."
ai_bot_enabled: "הפעלת מודול בוט הבינה המלאכותית."
Expand All @@ -106,7 +106,7 @@ he:
reports:
overall_sentiment:
title: "רגש כללי"
description: 'התרשים משווה את מספר הפוסטים שמסווגים כחיוביים או שליליים. אלו מחושבים כאשר ניקוד חיובי או שלילי הוא גדול מהדף הניוקוד המוגדר. משמעות הדבר היא שפוסטים נייטרליים לא מופיעים. הודעות פרטיות מוחרגות גם כן. מסווגות עם „cardiffnlp/twitter-roberta-base-sentiment-latest”'
description: "התרשים משווה את מספר הפוסטים שמסווגים כחיוביים או שליליים. אלו מחושבים כאשר ניקוד חיובי או שלילי הוא גדול מהדף הניוקוד המוגדר. משמעות הדבר היא שפוסטים נייטרליים לא מופיעים. הודעות פרטיות מוחרגות גם כן. מסווגות עם „cardiffnlp/twitter-roberta-base-sentiment-latest”"
xaxis: "חיובי(%)"
yaxis: "תאריך"
emotion_anger:
Expand Down
10 changes: 5 additions & 5 deletions config/locales/server.uk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ uk:
ai_summarization_model: "Модель для узагальнення."
ai_custom_summarization_allowed_groups: "Групи, яким дозволено створювати нові зведення."
ai_pm_summarization_allowed_groups: "Групи дозволили створювати та переглядати підсумки в особистих повідомленнях."
ai_summarize_max_hot_topics_gists_per_batch: "Після оновлення тем у гарячому списку ми згенеруємо короткі підсумки перших N. (Вимкнено, коли 0)"
ai_summary_gists_enabled: "Після оновлення тем у гарячому списку ми згенеруємо короткі підсумки перших N. (Вимкнено, коли 0)"
ai_hot_topic_gists_allowed_groups: "Групи, яким дозволено бачити суть у списку гарячих тем."
ai_summary_backfill_maximum_topics_per_hour: "Кількість підсумків тем для заповнення на годину."
ai_bot_enabled: "Увімкніть модуль AI Bot."
Expand Down Expand Up @@ -216,7 +216,7 @@ uk:
description: "Максимальна кількість результатів для включення в пошук – якщо порожні, будуть використані правила за замовчуванням, а кількість буде масштабовано залежно від моделі, що використовується. Найвище значення 100."
base_query:
name: "Базовий пошуковий запит"
description: "Базовий запит для пошуку. Приклад: \"#urgent\" додасть \"#urgent\" до пошукового запиту і знайде лише теми з категорією або тегом \"терміново\"."
description: 'Базовий запит для пошуку. Приклад: "#urgent" додасть "#urgent" до пошукового запиту і знайде лише теми з категорією або тегом "терміново".'
tool_summary:
web_browser: "Перегляд веб-сторінок"
github_search_files: "Пошук файлів на GitHub"
Expand Down Expand Up @@ -285,17 +285,17 @@ uk:
one: "Знайдено %{count} <a href='%{url}'>результат</a> для '%{query}'"
few: "Знайдено %{count} <a href='%{url}'>результати</a> для '%{query}'"
many: "Знайдено %{count} <a href='%{url}'>результатів</a> для '%{query}'"
other: "Знайдено %{count} <a href='%{url}'>результатів</a> для \"%{query}\""
other: 'Знайдено %{count} <a href=''%{url}''>результатів</a> для "%{query}"'
search_meta_discourse:
one: "Знайдено %{count} <a href='%{url}'>результат</a> для '%{query}'"
few: "Знайдено %{count} <a href='%{url}'>результати</a> для '%{query}'"
many: "Знайдено %{count} <a href='%{url}'>результатів</a> для '%{query}'"
other: "Знайдено %{count} <a href='%{url}'>результатів</a> для \"%{query}\""
other: 'Знайдено %{count} <a href=''%{url}''>результатів</a> для "%{query}"'
google:
one: "Знайдено %{count} <a href='%{url}'>результат</a> для '%{query}'"
few: "Знайдено %{count} <a href='%{url}'>результати</a> для '%{query}'"
many: "Знайдено %{count} <a href='%{url}'>результатів</a> для '%{query}'"
other: "Знайдено %{count} <a href='%{url}'>результатів</a> для \"%{query}\""
other: 'Знайдено %{count} <a href=''%{url}''>результатів</a> для "%{query}"'
setting_context: "Читання контексту для: %{setting_name}"
schema: "%{tables}"
search_settings:
Expand Down
8 changes: 3 additions & 5 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,10 @@ discourse_ai:
type: group_list
list_type: compact
default: "3|13" # 3: @staff, 13: @trust_level_3
ai_summarize_max_hot_topics_gists_per_batch:
default: 0
min: 0
max: 1000
ai_summary_gists_enabled:
default: false
hidden: true
ai_hot_topic_gists_allowed_groups:
ai_summary_gists_allowed_groups:
type: group_list
list_type: compact
default: ""
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20241126033812_rename_ai_gist_batch_setting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class RenameAiGistBatchSetting < ActiveRecord::Migration[7.0]
def up
execute "UPDATE site_settings SET name = 'ai_summary_gists_allowed_groups' WHERE name = 'ai_hot_topic_gists_allowed_groups'"
end

def down
execute "UPDATE site_settings SET name = 'ai_hot_topic_gists_allowed_groups' WHERE name = 'ai_summary_gists_allowed_groups'"
end
end
2 changes: 1 addition & 1 deletion lib/guardian_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def can_see_summary?(target)

def can_see_gists?
return false if !SiteSetting.ai_summarization_enabled
return false if SiteSetting.ai_summarize_max_hot_topics_gists_per_batch.zero?
return false if SiteSetting.ai_summary_gists_enabled
if SiteSetting.ai_hot_topic_gists_allowed_groups.to_s == Group::AUTO_GROUPS[:everyone].to_s
return true
end
Expand Down
14 changes: 3 additions & 11 deletions lib/summarization/entry_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def inject_into(plugin)

plugin.register_modifier(:topic_query_create_list_topics) do |topics, options|
if Discourse.filters.include?(options[:filter]) && SiteSetting.ai_summarization_enabled &&
SiteSetting.ai_summarize_max_hot_topics_gists_per_batch > 0
SiteSetting.ai_summary_gists_enabled
topics.includes(:ai_gist_summary)
else
topics
Expand All @@ -35,20 +35,12 @@ def inject_into(plugin)
object.ai_gist_summary&.summarized_text
end

# To make sure hot topic gists are inmediately up to date, we rely on this event
# instead of using a scheduled job.
plugin.on(:topic_hot_scores_updated) { Jobs.enqueue(:hot_topics_gist_batch) }

# As this event can be triggered quite often, let's be overly cautious enqueueing
# jobs if the feature is disabled.
plugin.on(:post_created) do |post|
if SiteSetting.discourse_ai_enabled && SiteSetting.ai_summarization_enabled &&
SiteSetting.ai_summarize_max_hot_topics_gists_per_batch > 0 && post.topic
hot_score = TopicHotScore.find_by(topic: post.topic)

if hot_score.present? && hot_score.updated_at > 1.day.ago
Jobs.enqueue(:update_hot_topic_gist, topic_id: post&.topic_id)
end
SiteSetting.ai_summary_gists_enabled > 0 && post.topic
Jobs.enqueue(:fast_track_topic_gist, topic_id: post&.topic_id)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Jobs::UpdateHotTopicGist do
RSpec.describe Jobs::FastTrackTopicGist do
describe "#execute" do
fab!(:topic_1) { Fabricate(:topic) }
fab!(:post_1) { Fabricate(:post, topic: topic_1, post_number: 1) }
Expand All @@ -9,11 +9,10 @@
before do
assign_fake_provider_to(:ai_summarization_model)
SiteSetting.ai_summarization_enabled = true
SiteSetting.ai_summarize_max_hot_topics_gists_per_batch = 100
SiteSetting.ai_summary_gists_enabled = true
end

context "when the hot topic has a gist" do
before { TopicHotScore.create!(topic_id: topic_1.id, score: 0.1) }
context "when the topic has a gist" do
fab!(:ai_gist) do
Fabricate(:topic_ai_gist, target: topic_1, original_content_sha: AiSummary.build_sha("12"))
end
Expand Down Expand Up @@ -48,22 +47,22 @@
end

context "when the topic doesn't have a hot topic score" do
it "does nothing" do
subject.execute({})
it "creates gist" do
subject.execute(topic_id: topic_1.id)

gist = AiSummary.gist.find_by(target: topic_1)
expect(gist).to be_nil
expect(gist).to be_present
end
end

context "when the topic has a hot topic score but no gist" do
before { TopicHotScore.create!(topic_id: topic_1.id, score: 0.1) }

it "does nothing" do
subject.execute({})
it "creates gist" do
subject.execute(topic_id: topic_1.id)

gist = AiSummary.gist.find_by(target: topic_1)
expect(gist).to be_nil
expect(gist).to be_present
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/jobs/regular/hot_topics_gist_batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
before do
assign_fake_provider_to(:ai_summarization_model)
SiteSetting.ai_summarization_enabled = true
SiteSetting.ai_summarize_max_hot_topics_gists_per_batch = 100
SiteSetting.ai_summary_gists_enabled = true
end

describe "#execute" do
Expand All @@ -34,7 +34,7 @@
end

it "does nothing if hot topics summarization is disabled" do
SiteSetting.ai_summarize_max_hot_topics_gists_per_batch = 0
SiteSetting.ai_summary_gists_enabled = false

subject.execute({})

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/guardian_extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
group.add(user)
assign_fake_provider_to(:ai_summarization_model)
SiteSetting.ai_summarization_enabled = true
SiteSetting.ai_summarize_max_hot_topics_gists_per_batch = 1
SiteSetting.ai_summary_gists_enabled = true
end

let(:anon_guardian) { Guardian.new }
Expand Down
13 changes: 2 additions & 11 deletions spec/lib/modules/summarization/entry_point_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
before do
assign_fake_provider_to(:ai_summarization_model)
SiteSetting.ai_summarization_enabled = true
SiteSetting.ai_summarize_max_hot_topics_gists_per_batch = 100
SiteSetting.ai_summary_gists_enabled = true
end

fab!(:user)
Expand Down Expand Up @@ -63,7 +63,7 @@
before do
group.add(user)
SiteSetting.ai_hot_topic_gists_allowed_groups = group.id
SiteSetting.ai_summarize_max_hot_topics_gists_per_batch = 100
SiteSetting.ai_summary_gists_enabled = true
end

it "includes the summary" do
Expand Down Expand Up @@ -153,13 +153,4 @@
end
end
end

describe "#on topic_hot_scores_updated" do
it "queues a job to generate gists" do
expect { DiscourseEvent.trigger(:topic_hot_scores_updated) }.to change(
Jobs::HotTopicsGistBatch.jobs,
:size,
).by(1)
end
end
end
Loading