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

Commit 0fadf1d

Browse files
committed
DEV: update enumerator
1 parent c26d604 commit 0fadf1d

14 files changed

+51
-40
lines changed

config/locales/client.en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ en:
567567
max_usages_required: "Must be set if max tokens is not set"
568568
usage:
569569
ai_bot: "AI bot"
570-
ai_helper: "Helper"
570+
ai_helper: "Helper (%{persona})"
571571
ai_helper_image_caption: "Image caption"
572572
ai_persona: "Persona (%{persona})"
573573
ai_summarization: "Summarize"

config/settings.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ discourse_ai:
272272
type: enum
273273
allow_any: false
274274
enum: "DiscourseAi::Configuration::LlmEnumerator"
275-
validator: "DiscourseAi::Configuration::LlmValidator"
276275
area: "ai-features/embeddings"
277276
ai_embeddings_semantic_search_hyde_model_allowed_seeded_models:
278277
default: ""
@@ -328,7 +327,6 @@ discourse_ai:
328327
allow_any: false
329328
type: enum
330329
enum: "DiscourseAi::Configuration::LlmEnumerator"
331-
validator: "DiscourseAi::Configuration::LlmValidator"
332330
hidden: true
333331
ai_summarization_persona:
334332
default: "-11"
@@ -495,7 +493,6 @@ discourse_ai:
495493
type: enum
496494
allow_any: false
497495
enum: "DiscourseAi::Configuration::LlmEnumerator"
498-
validator: "DiscourseAi::Configuration::LlmValidator"
499496
area: "ai-features/translation"
500497
ai_translation_locale_detector_persona:
501498
default: "-27"

lib/configuration/llm_enumerator.rb

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
module DiscourseAi
66
module Configuration
77
class LlmEnumerator < ::EnumSiteSetting
8-
# TODO: global_usage is no longer accurate, it should be removed/updated
98
def self.global_usage
109
rval = Hash.new { |h, k| h[k] = [] }
1110

@@ -23,24 +22,53 @@ def self.global_usage
2322
.each { |llm_id, name, id| rval[llm_id] << { type: :ai_persona, name: name, id: id } }
2423

2524
if SiteSetting.ai_helper_enabled
26-
model_id = SiteSetting.ai_helper_model.split(":").last.to_i
27-
rval[model_id] << { type: :ai_helper } if model_id != 0
25+
{
26+
"#{I18n.t("js.discourse_ai.features.ai_helper.proofread")}" =>
27+
SiteSetting.ai_helper_proofreader_persona,
28+
"#{I18n.t("js.discourse_ai.features.ai_helper.title_suggestions")}" =>
29+
SiteSetting.ai_helper_title_suggestions_persona,
30+
"#{I18n.t("js.discourse_ai.features.ai_helper.explain")}" =>
31+
SiteSetting.ai_helper_explain_persona,
32+
"#{I18n.t("js.discourse_ai.features.ai_helper.illustrate_post")}" =>
33+
SiteSetting.ai_helper_post_illustrator_persona,
34+
"#{I18n.t("js.discourse_ai.features.ai_helper.smart_dates")}" =>
35+
SiteSetting.ai_helper_smart_dates_persona,
36+
"#{I18n.t("js.discourse_ai.features.ai_helper.translator")}" =>
37+
SiteSetting.ai_helper_translator_persona,
38+
"#{I18n.t("js.discourse_ai.features.ai_helper.markdown_tables")}" =>
39+
SiteSetting.ai_helper_markdown_tables_persona,
40+
"#{I18n.t("js.discourse_ai.features.ai_helper.custom_prompt")}" =>
41+
SiteSetting.ai_helper_custom_prompt_persona,
42+
}.each do |helper_type, persona_id|
43+
next if persona_id.blank?
44+
45+
persona = AiPersona.find_by(id: persona_id)
46+
next if persona.blank? || persona.default_llm_id.blank?
47+
48+
model_id = persona.default_llm_id || SiteSetting.ai_default_llm_model.to_i
49+
rval[model_id] << { type: :ai_helper, name: helper_type }
50+
end
2851
end
2952

30-
if SiteSetting.ai_helper_image_caption_model
31-
model_id = SiteSetting.ai_helper_image_caption_model.split(":").last.to_i
32-
rval[model_id] << { type: :ai_helper_image_caption } if model_id != 0
53+
if SiteSetting.ai_helper_enabled_features.split("|").include?("image_caption")
54+
image_caption_persona = AiPersona.find_by(id: SiteSetting.ai_helper_image_caption_persona)
55+
model_id = image_caption_persona.default_llm_id || SiteSetting.ai_default_llm_model.to_i
56+
57+
rval[model_id] << { type: :ai_helper_image_caption }
3358
end
3459

3560
if SiteSetting.ai_summarization_enabled
3661
summarization_persona = AiPersona.find_by(id: SiteSetting.ai_summarization_persona)
37-
model_id = summarization_persona.default_llm_id || LlmModel.last&.id
62+
model_id = summarization_persona.default_llm_id || SiteSetting.ai_default_llm_model.to_i
3863

3964
rval[model_id] << { type: :ai_summarization }
4065
end
4166

4267
if SiteSetting.ai_embeddings_semantic_search_enabled
43-
model_id = SiteSetting.ai_embeddings_semantic_search_hyde_model.split(":").last.to_i
68+
search_persona =
69+
AiPersona.find_by(id: SiteSetting.ai_embeddings_semantic_search_hyde_persona)
70+
model_id = search_persona.default_llm_id || SiteSetting.ai_default_llm_model.to_i
71+
4472
rval[model_id] << { type: :ai_embeddings_semantic_search }
4573
end
4674

lib/configuration/llm_validator.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ def run_test(val)
3535
end
3636

3737
def modules_using(llm_model)
38-
choose_llm_settings = modules_and_choose_llm_settings.values
38+
in_use_llms = AiPersona.where.not(default_llm_id: nil).pluck(:default_llm_id)
39+
default_llm = SiteSetting.ai_default_llm_model.presence&.to_i
3940

40-
choose_llm_settings.select { |s| SiteSetting.public_send(s) == "custom:#{llm_model.id}" }
41+
combined_llms = (in_use_llms + [default_llm]).compact.uniq
42+
combined_llms
4143
end
4244

4345
def error_message

spec/configuration/llm_enumerator_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
describe "#global_usage" do
4343
it "returns a hash of Llm models in use globally" do
44-
SiteSetting.ai_helper_model = "custom:#{fake_model.id}"
44+
assign_fake_provider_to(:ai_default_llm_model)
4545
SiteSetting.ai_helper_enabled = true
4646
expect(described_class.global_usage).to eq(fake_model.id => [{ type: :ai_helper }])
4747
end

spec/jobs/regular/detect_translate_post_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
let(:locales) { %w[en ja] }
88

99
before do
10+
assign_fake_provider_to(:ai_default_llm_model)
1011
SiteSetting.discourse_ai_enabled = true
11-
Fabricate(:fake_model).tap do |fake_llm|
12-
SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")
13-
end
1412
SiteSetting.ai_translation_enabled = true
1513
SiteSetting.content_localization_supported_locales = locales.join("|")
1614
end

spec/jobs/regular/detect_translate_topic_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
let(:locales) { %w[en ja] }
88

99
before do
10+
assign_fake_provider_to(:ai_default_llm_model)
1011
SiteSetting.discourse_ai_enabled = true
11-
Fabricate(:fake_model).tap do |fake_llm|
12-
SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")
13-
end
1412
SiteSetting.ai_translation_enabled = true
1513
SiteSetting.content_localization_supported_locales = locales.join("|")
1614
end

spec/jobs/regular/localize_categories_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ def localize_all_categories(*locales)
1010
end
1111

1212
before do
13+
assign_fake_provider_to(:ai_default_llm_model)
1314
SiteSetting.discourse_ai_enabled = true
14-
Fabricate(:fake_model).tap do |fake_llm|
15-
SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")
16-
end
1715
SiteSetting.ai_translation_enabled = true
1816
SiteSetting.content_localization_supported_locales = "pt_BR|zh_CN"
1917

spec/jobs/regular/localize_posts_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
let(:locales) { %w[en ja de] }
88

99
before do
10+
assign_fake_provider_to(:ai_default_llm_model)
1011
SiteSetting.discourse_ai_enabled = true
11-
Fabricate(:fake_model).tap do |fake_llm|
12-
SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")
13-
end
1412
SiteSetting.ai_translation_enabled = true
1513
SiteSetting.content_localization_supported_locales = locales.join("|")
1614
SiteSetting.ai_translation_backfill_hourly_rate = 100

spec/jobs/regular/localize_topics_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
let(:locales) { %w[en ja de] }
88

99
before do
10+
assign_fake_provider_to(:ai_default_llm_model)
1011
SiteSetting.discourse_ai_enabled = true
11-
Fabricate(:fake_model).tap do |fake_llm|
12-
SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")
13-
end
1412
SiteSetting.ai_translation_enabled = true
1513
SiteSetting.content_localization_supported_locales = locales.join("|")
1614
SiteSetting.ai_translation_backfill_hourly_rate = 100

0 commit comments

Comments
 (0)