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

Commit f593ab6

Browse files
committed
DEV: remove custom: prefix
and update migrations for translations
1 parent b58f198 commit f593ab6

14 files changed

+75
-106
lines changed

app/models/llm_model.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def to_llm
9999
end
100100

101101
def identifier
102-
"custom:#{id}"
102+
"#{id}"
103103
end
104104

105105
def toggle_companion_user

assets/javascripts/discourse/components/ai-spam.gjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default class AiSpam extends Component {
9090
this.isEnabled = model.is_enabled;
9191

9292
if (model.llm_id) {
93-
this.selectedLLM = "custom:" + model.llm_id;
93+
this.selectedLLM = model.llm_id;
9494
} else {
9595
if (this.availableLLMs.length) {
9696
this.selectedLLM = this.availableLLMs[0].id;

config/settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ discourse_ai:
1616
type: enum
1717
allow_any: false
1818
enum: "DiscourseAi::Configuration::LlmEnumerator"
19-
validator: "DiscourseAi::Configuration::SimpleLlmValidator"
19+
validator: "DiscourseAi::Configuration::LlmValidator"
2020

2121
ai_sentiment_enabled:
2222
default: false

db/migrate/20250710173803_seed_ai_default_llm_model.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def up
66
last_model_id = DB.query_single("SELECT id FROM llm_models ORDER BY id DESC LIMIT 1").first
77

88
if last_model_id.present?
9-
execute "UPDATE site_settings SET value = 'custom:#{last_model_id}' WHERE name = 'ai_default_llm_model' AND (value IS NULL OR value = '');"
9+
execute "UPDATE site_settings SET value = '#{last_model_id}' WHERE name = 'ai_default_llm_model' AND (value IS NULL OR value = '');"
1010
end
1111
end
1212

db/migrate/20250710181656_copy_ai_helper_model_to_persona_default.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def up
1212
execute(<<~SQL)
1313
UPDATE ai_personas
1414
SET default_llm_id = #{model_id}
15-
WHERE id IN (-18, -19, -20, -21, -22, -23, -24, -25, -26) AND default_llm_id IS NULL
15+
WHERE id IN (-18, -19, -20, -21, -22, -23, -24, -25) AND default_llm_id IS NULL
1616
SQL
1717
end
1818
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
class CopyTranslationModelToPersona < ActiveRecord::Migration[7.2]
3+
def up
4+
ai_translation_model =
5+
DB.query_single("SELECT value FROM site_settings WHERE name = 'ai_translation_model'").first
6+
7+
if ai_translation_model.present? && ai_translation_model.start_with?("custom:")
8+
# Extract the model ID from the setting value (e.g., "custom:-5" -> "-5")
9+
model_id = ai_translation_model.split(":").last
10+
11+
# Update the translation personas (IDs -27, -28, -29, -30) with the extracted model ID
12+
execute(<<~SQL)
13+
UPDATE ai_personas
14+
SET default_llm_id = #{model_id}
15+
WHERE id IN (-27, -28, -29, -30) AND default_llm_id IS NULL
16+
SQL
17+
end
18+
end
19+
20+
def down
21+
raise ActiveRecord::IrreversibleMigration
22+
end
23+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
class CopyAiImageCaptionModelToPersonaDefault < ActiveRecord::Migration[7.2]
3+
def up
4+
ai_helper_image_caption_model =
5+
DB.query_single(
6+
"SELECT value FROM site_settings WHERE name = 'ai_helper_image_caption_model'",
7+
).first
8+
9+
if ai_helper_image_caption_model.present? &&
10+
ai_helper_image_caption_model.start_with?("custom:")
11+
# Extract the model ID from the setting value (e.g., "custom:1" -> "1")
12+
model_id = ai_helper_image_caption_model.split(":").last
13+
14+
# Update the helper personas with the extracted model ID
15+
execute(<<~SQL)
16+
UPDATE ai_personas
17+
SET default_llm_id = #{model_id}
18+
WHERE id IN (-26) AND default_llm_id IS NULL
19+
SQL
20+
end
21+
end
22+
23+
def down
24+
raise ActiveRecord::IrreversibleMigration
25+
end
26+
end

lib/ai_helper/assistant.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -314,19 +314,11 @@ def find_ai_helper_model(helper_mode, persona_klass)
314314
# 1. Persona's default LLM
315315
# 2. SiteSetting.ai_default_llm_id (or newest LLM if not set)
316316
def self.find_ai_helper_model(helper_mode, persona_klass)
317-
model_id =
318-
persona_klass.default_llm_id || SiteSetting.ai_default_llm_model&.split(":")&.last # Remove legacy custom provider.
317+
model_id = persona_klass.default_llm_id || SiteSetting.ai_default_llm_model
319318

320319
if model_id.present?
321320
LlmModel.find_by(id: model_id)
322321
else
323-
last_model_id = LlmModel.last&.id
324-
325-
# SiteSetting.ai_default_llm_model shouldn't be empty, but if it is, we set it to the last model.
326-
if last_model_id.present? && SiteSetting.ai_default_llm_model.empty?
327-
SiteSetting.set_and_log("ai_default_llm_model", "custom:#{last_model_id}", Discourse.system_user) # Remove legacy custom provider.
328-
end
329-
330322
LlmModel.last
331323
end
332324
end

lib/configuration/llm_enumerator.rb

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

@@ -107,7 +108,6 @@ def self.values(allowed_seeded_llms: nil)
107108
end
108109
end
109110

110-
values.each { |value_h| value_h[:value] = "custom:#{value_h[:value]}" }
111111
values
112112
end
113113
end

lib/configuration/llm_validator.rb

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
module DiscourseAi
44
module Configuration
5-
class InvalidSeededModelError < StandardError
6-
end
7-
85
class LlmValidator
96
def initialize(opts = {})
107
@opts = opts
@@ -18,19 +15,19 @@ def valid_value?(val)
1815
return !@parent_enabled
1916
end
2017

21-
allowed_seeded_model?(val)
22-
2318
run_test(val).tap { |result| @unreachable = result }
24-
rescue DiscourseAi::Configuration::InvalidSeededModelError => e
25-
@unreachable = true
26-
false
2719
rescue StandardError => e
2820
raise e if Rails.env.test?
2921
@unreachable = true
3022
true
3123
end
3224

3325
def run_test(val)
26+
if Rails.env.test?
27+
# In test mode, we assume the model is reachable.
28+
return true
29+
end
30+
3431
DiscourseAi::Completions::Llm
3532
.proxy(val)
3633
.generate("How much is 1 + 1?", user: nil, feature_name: "llm_validator")
@@ -53,10 +50,6 @@ def error_message
5350
)
5451
end
5552

56-
if @invalid_seeded_model
57-
return I18n.t("discourse_ai.llm.configuration.invalid_seeded_model")
58-
end
59-
6053
return unless @unreachable
6154

6255
I18n.t("discourse_ai.llm.configuration.model_unreachable")
@@ -68,25 +61,12 @@ def choose_llm_setting_for(module_enabler_setting)
6861

6962
def modules_and_choose_llm_settings
7063
{
71-
ai_embeddings_semantic_search_enabled: :ai_embeddings_semantic_search_hyde_model,
72-
ai_helper_enabled: :ai_helper_model,
73-
ai_summarization_enabled: :ai_summarization_model,
74-
ai_translation_enabled: :ai_translation_model,
64+
ai_embeddings_semantic_search_enabled: :ai_default_llm_model,
65+
ai_helper_enabled: :ai_default_llm_model,
66+
ai_summarization_enabled: :ai_default_llm_model,
67+
ai_translation_enabled: :ai_default_llm_model,
7568
}
7669
end
77-
78-
def allowed_seeded_model?(val)
79-
id = val.split(":").last
80-
return true if id.to_i > 0
81-
82-
setting = @opts[:name]
83-
allowed_list = SiteSetting.public_send("#{setting}_allowed_seeded_models")
84-
85-
if allowed_list.split("|").exclude?(id)
86-
@invalid_seeded_model = true
87-
raise DiscourseAi::Configuration::InvalidSeededModelError.new
88-
end
89-
end
9070
end
9171
end
9272
end

0 commit comments

Comments
 (0)