A platform for community discussion. Free, open, simple.
FEATURE: configure a default LLM model for all features (#33752)
Roman Rizzi2c1535a39ce9
diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_llms_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_llms_controller.rbindex 68cb24c7206..702fcddac40 100644--- a/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_llms_controller.rb+++ b/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_llms_controller.rb@@ -100,7 +100,7 @@ module DiscourseAireturn render_json_error(I18n.t("discourse_ai.llm.cannot_delete_builtin"), status: 403)end- in_use_by = DiscourseAi::Configuration::LlmValidator.new.modules_using(llm_model)+ in_use_by = DiscourseAi::Configuration::LlmValidator.new.is_using(llm_model)if !in_use_by.empty?return(diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_spam_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_spam_controller.rbindex 194903919d3..4889da871ef 100644--- a/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_spam_controller.rb+++ b/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_spam_controller.rb@@ -24,17 +24,6 @@ module DiscourseAiupdated_params = {}if allowed_params.key?(:llm_model_id)llm_model_id = updated_params[:llm_model_id] = allowed_params[:llm_model_id]- if llm_model_id.to_i < 0 &&- !SiteSetting.ai_spam_detection_model_allowed_seeded_models_map.include?(- llm_model_id.to_s,- )- return(- render_json_error(- I18n.t("discourse_ai.llm.configuration.invalid_seeded_model"),- status: 422,- )- )- endendif allowed_params.key?(:ai_persona_id)diff --git a/plugins/discourse-ai/app/jobs/regular/stream_discover_reply.rb b/plugins/discourse-ai/app/jobs/regular/stream_discover_reply.rbindex 3e6e9594d58..d60dea4a5c4 100644--- a/plugins/discourse-ai/app/jobs/regular/stream_discover_reply.rb+++ b/plugins/discourse-ai/app/jobs/regular/stream_discover_reply.rb@@ -16,7 +16,9 @@ module Jobsif ai_persona_klass.nil? || !user.in_any_groups?(ai_persona_klass.allowed_group_ids.to_a)returnend- return if (llm_model = LlmModel.find_by(id: ai_persona_klass.default_llm_id)).nil?++ llm_model_id = ai_persona_klass.default_llm_id || SiteSetting.default_llm_id+ return if (llm_model = LlmModel.find_by(id: llm_model_id)).nil?bot =DiscourseAi::Personas::Bot.as(diff --git a/plugins/discourse-ai/app/models/ai_persona.rb b/plugins/discourse-ai/app/models/ai_persona.rbindex 4c40b5c8fbe..694cde78027 100644--- a/plugins/discourse-ai/app/models/ai_persona.rb+++ b/plugins/discourse-ai/app/models/ai_persona.rb@@ -12,7 +12,6 @@ class AiPersona < ActiveRecord::Basevalidates :system_prompt, presence: true, length: { maximum: 10_000_000 }validate :system_persona_unchangeable, on: :update, if: :systemvalidate :chat_preconditions- validate :allowed_seeded_model, if: :default_llm_idvalidate :well_formated_examplesvalidates :max_context_posts, numericality: { greater_than: 0 }, allow_nil: true# leaves some room for growth but sets a maximum to avoid memory issues@@ -365,17 +364,6 @@ class AiPersona < ActiveRecord::Baseendend- def allowed_seeded_model- return if default_llm_id.blank?-- return if default_llm.nil?- return if !default_llm.seeded?-- return if SiteSetting.ai_bot_allowed_seeded_models_map.include?(default_llm.id.to_s)-- errors.add(:default_llm, I18n.t("discourse_ai.llm.configuration.invalid_seeded_model"))- end-def well_formated_examplesreturn if examples.blank?diff --git a/plugins/discourse-ai/app/models/llm_model.rb b/plugins/discourse-ai/app/models/llm_model.rbindex 937c5373b83..7834d065b31 100644--- a/plugins/discourse-ai/app/models/llm_model.rb+++ b/plugins/discourse-ai/app/models/llm_model.rb@@ -99,7 +99,7 @@ class LlmModel < ActiveRecord::Baseenddef identifier- "custom:#{id}"+ "#{id}"enddef toggle_companion_userdiff --git a/plugins/discourse-ai/app/serializers/ai_spam_serializer.rb b/plugins/discourse-ai/app/serializers/ai_spam_serializer.rbindex dc1212d36f9..12e5e3dc606 100644--- a/plugins/discourse-ai/app/serializers/ai_spam_serializer.rb+++ b/plugins/discourse-ai/app/serializers/ai_spam_serializer.rb@@ -30,9 +30,9 @@ class AiSpamSerializer < ApplicationSerializerenddef available_llms- DiscourseAi::Configuration::LlmEnumerator- .values(allowed_seeded_llms: SiteSetting.ai_spam_detection_model_allowed_seeded_models_map)- .map { |hash| { id: hash[:value], name: hash[:name] } }+ DiscourseAi::Configuration::LlmEnumerator.values.map do |hash|+ { id: hash[:value], name: hash[:name] }+ endenddef available_personasdiff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-default-llm-selector.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-default-llm-selector.gjsnew file mode 100644index 00000000000..9a28c7b75cc--- /dev/null+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-default-llm-selector.gjs@@ -0,0 +1,46 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { ajax } from "discourse/lib/ajax";+import { i18n } from "discourse-i18n";+import SiteSettingComponent from "admin/components/site-setting";+import SiteSetting from "admin/models/site-setting";++export default class AiDefaultLlmSelector extends Component {+ @tracked defaultLlmSetting = null;++ constructor() {+ super(...arguments);+ this.#loadDefaultLlmSetting();+ }++ async #loadDefaultLlmSetting() {+ const { site_settings } = await ajax("/admin/config/site_settings.json", {+ data: {+ plugin: "discourse-ai",+ category: "discourse_ai",+ },+ });++ const defaultLlmSetting = site_settings.find(+ (setting) => setting.setting === "ai_default_llm_model"+ );++ this.defaultLlmSetting = SiteSetting.create(defaultLlmSetting);+ }++ <template>+ <div class="ai-configure-default-llm">+ <div class="ai-configure-default-llm__header">+ <h3>{{i18n "discourse_ai.default_llm.title"}}</h3>+ <p>{{i18n "discourse_ai.default_llm.description"}}</p>+ </div>++ {{#if this.defaultLlmSetting}}+ <SiteSettingComponent+ @setting={{this.defaultLlmSetting}}+ class="ai-configure-default-llm__setting"+ />+ {{/if}}+ </div>+ </template>+}diff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-features.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-features.gjsindex 45f1b12ef29..8c762fc0d5c 100644--- a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-features.gjs+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-features.gjs@@ -9,6 +9,7 @@ import DPageSubheader from "discourse/components/d-page-subheader";import DSelect from "discourse/components/d-select";import FilterInput from "discourse/components/filter-input";import { i18n } from "discourse-i18n";+import AiDefaultLlmSelector from "./ai-default-llm-selector";import AiFeaturesList from "./ai-features-list";const ALL = "all";@@ -202,6 +203,8 @@ export default class AiFeatures extends Component {/></div>+ <AiDefaultLlmSelector />+{{#if this.filteredFeatures.length}}<AiFeaturesList @modules={{this.filteredFeatures}} />{{else}}diff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-llms-list-editor.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-llms-list-editor.gjsindex 08f1715c861..8d70b43508b 100644--- a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-llms-list-editor.gjs+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-llms-list-editor.gjs@@ -9,6 +9,7 @@ import I18n, { i18n } from "discourse-i18n";import AdminSectionLandingItem from "admin/components/admin-section-landing-item";import AdminSectionLandingWrapper from "admin/components/admin-section-landing-wrapper";import DTooltip from "float-kit/components/d-tooltip";+import AiDefaultLlmSelector from "./ai-default-llm-selector";import AiLlmEditor from "./ai-llm-editor";function isPreseeded(llm) {@@ -137,6 +138,9 @@ export default class AiLlmsListEditor extends Component {}}@learnMoreUrl="https://meta.discourse.org/t/discourse-ai-large-language-model-llm-settings-page/319903"/>++ <AiDefaultLlmSelector />+{{#if this.hasLlmElements}}<section class="ai-llms-list-editor__configured"><DPageSubheaderdiff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-spam.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-spam.gjsindex fdfa02d0691..ea69e54293c 100644--- a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-spam.gjs+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-spam.gjs@@ -90,7 +90,7 @@ export default class AiSpam extends Component {this.isEnabled = model.is_enabled;if (model.llm_id) {- this.selectedLLM = "custom:" + model.llm_id;+ this.selectedLLM = model.llm_id;} else {if (this.availableLLMs.length) {this.selectedLLM = this.availableLLMs[0].id;@@ -127,7 +127,7 @@ export default class AiSpam extends Component {}get llmId() {- return this.selectedLLM.toString().split(":")[1];+ return this.selectedLLM;}@actiondiff --git a/plugins/discourse-ai/assets/stylesheets/common/ai-features.scss b/plugins/discourse-ai/assets/stylesheets/common/ai-features.scssindex 63686965267..70c985fa371 100644--- a/plugins/discourse-ai/assets/stylesheets/common/ai-features.scss+++ b/plugins/discourse-ai/assets/stylesheets/common/ai-features.scss@@ -155,3 +155,51 @@.ai-expanded-list__toggle-button {padding: 0;}++.ai-configure-default-llm {+ display: flex;+ align-items: center;+ gap: var(--space-2);+ background: var(--primary-very-low);+ padding: 1rem;+ margin-block: 1rem;+ border-radius: var(--d-border-radius);++ &__header {+ flex: 3;+ }++ &__setting {+ flex: 2;+ display: flex;+ gap: var(--space-2);+ align-items: center;+ justify-content: center;++ .setting-controls__undo {+ display: none;+ }+ }++ h3 {+ color: var(--primary);+ font-size: var(--font-0);+ margin-bottom: 0;+ }++ p {+ margin-top: 0;+ font-size: var(--font-down-1);+ color: var(--primary-high-or-secondary-low);+ }++ .select-kit,+ .btn {+ font-size: var(--font-down-1);+ }++ .setting-label,+ .desc {+ display: none;+ }+}diff --git a/plugins/discourse-ai/config/locales/client.en.yml b/plugins/discourse-ai/config/locales/client.en.ymlindex 6166d661722..eecd0ad1230 100644--- a/plugins/discourse-ai/config/locales/client.en.yml+++ b/plugins/discourse-ai/config/locales/client.en.yml@@ -187,6 +187,10 @@ en:discourse_ai:title: "AI"+ default_llm:+ title: "Default LLM model"+ description: "The default LLM model to use for all AI features. This will be used if no LLM is specified in the feature configuration or persona. If no default LLM is specified, the last created LLM will be used."+features:short_title: "Features"description: "These are the AI features available to visitors on your site. These can be configured to use specific personas and LLMs, and can be access controlled by groups."@@ -569,7 +573,7 @@ en:max_usages_required: "Must be set if max tokens is not set"usage:ai_bot: "AI bot"- ai_helper: "Helper"+ ai_helper: "Helper (%{persona})"ai_helper_image_caption: "Image caption"ai_persona: "Persona (%{persona})"ai_summarization: "Summarize"diff --git a/plugins/discourse-ai/config/locales/server.en.yml b/plugins/discourse-ai/config/locales/server.en.ymlindex fbdf373c860..209551a2fb2 100644--- a/plugins/discourse-ai/config/locales/server.en.yml+++ b/plugins/discourse-ai/config/locales/server.en.yml@@ -25,6 +25,7 @@ en:description: "Periodic report based on a large language model"site_settings:discourse_ai_enabled: "Enable the discourse AI plugin."+ ai_default_llm_model: "The default LLM model to use for all AI features"ai_artifact_security: "The AI artifact system generates IFRAMEs with runnable code. Strict mode forces an extra click to run code. Lax mode runs code immediately. Hybrid mode allows user to supply data-ai-artifact-autorun to show right away. Disabled mode disables the artifact system."ai_toxicity_enabled: "Enable the toxicity module."ai_toxicity_inference_service_api_endpoint: "URL where the API is running for the toxicity module"@@ -581,7 +582,7 @@ en:llm:configuration:create_llm: "You need to setup an LLM before enabling this feature"- disable_module_first: "You have to disable %{setting} first."+ disable_modules_first: "You must disable these modules first: %{settings}"set_llm_first: "Set %{setting} first"model_unreachable: "We couldn't get a response from this model. Check your settings first."invalid_seeded_model: "You can't use this model with this feature"diff --git a/plugins/discourse-ai/config/settings.yml b/plugins/discourse-ai/config/settings.ymlindex f4cbd3085e3..c5e83c2cf61 100644--- a/plugins/discourse-ai/config/settings.yml+++ b/plugins/discourse-ai/config/settings.yml@@ -11,6 +11,12 @@ discourse_ai:- "lax"- "hybrid"- "strict"+ ai_default_llm_model:+ default: ""+ type: enum+ allow_any: false+ enum: "DiscourseAi::Configuration::LlmEnumerator"+ validator: "DiscourseAi::Configuration::LlmValidator"ai_sentiment_enabled:default: false@@ -103,7 +109,7 @@ discourse_ai:default: falseclient: truearea: "ai-features/ai_helper"- ai_helper_model:+ ai_helper_model: # Deprecated. TODO(keegan): Remove 2025-09-01default: ""allow_any: falsetype: enum@@ -149,17 +155,17 @@ discourse_ai:- "context_menu"- "image_caption"area: "ai-features/ai_helper"- ai_helper_image_caption_model:+ ai_helper_image_caption_model: # Deprecated. TODO(keegan): Remove 2025-09-01default: ""type: enumenum: "DiscourseAi::Configuration::LlmVisionEnumerator"hidden: true- ai_helper_model_allowed_seeded_models:+ ai_helper_model_allowed_seeded_models: # Deprecated. TODO(roman): Remove 2025-09-01default: ""hidden: truetype: listlist_type: compact- ai_helper_image_caption_model_allowed_seeded_models:+ ai_helper_image_caption_model_allowed_seeded_models: # Deprecated. TODO(roman): Remove 2025-09-01default: ""hidden: truetype: list@@ -252,14 +258,13 @@ discourse_ai:client: truevalidator: "DiscourseAi::Configuration::LlmDependencyValidator"area: "ai-features/embeddings"- ai_embeddings_semantic_search_hyde_model:+ ai_embeddings_semantic_search_hyde_model: # Deprecated. TODO(keegan): Remove 2025-09-01+ hidden: truedefault: ""type: enumallow_any: falseenum: "DiscourseAi::Configuration::LlmEnumerator"- validator: "DiscourseAi::Configuration::LlmValidator"- area: "ai-features/embeddings"- ai_embeddings_semantic_search_hyde_model_allowed_seeded_models:+ ai_embeddings_semantic_search_hyde_model_allowed_seeded_models: # Deprecated. TODO(roman): Remove 2025-09-01default: ""hidden: truetype: list@@ -308,12 +313,11 @@ discourse_ai:client: truevalidator: "DiscourseAi::Configuration::LlmDependencyValidator"area: "ai-features/summarization"- ai_summarization_model:+ ai_summarization_model: # Deprecated. TODO(keegan): Remove 2025-09-01default: ""allow_any: falsetype: enumenum: "DiscourseAi::Configuration::LlmEnumerator"- validator: "DiscourseAi::Configuration::LlmValidator"hidden: trueai_summarization_persona:default: "-11"@@ -343,7 +347,7 @@ discourse_ai:list_type: compactdefault: "0" #everyonehidden: true- ai_summarization_model_allowed_seeded_models:+ ai_summarization_model_allowed_seeded_models: # Deprecated. TODO(roman): Remove 2025-09-01default: ""hidden: truetype: list@@ -415,7 +419,7 @@ discourse_ai:ai_automation_max_triage_per_post_per_minute:default: 2hidden: true- ai_automation_allowed_seeded_models:+ ai_automation_allowed_seeded_models: # Deprecated. TODO(roman): Remove 2025-09-01default: ""hidden: truetype: list@@ -457,7 +461,7 @@ discourse_ai:ai_spam_detection_user_id:default: ""hidden: true- ai_spam_detection_model_allowed_seeded_models:+ ai_spam_detection_model_allowed_seeded_models: # Deprecated. TODO(roman): Remove 2025-09-01default: ""hidden: truetype: list@@ -475,13 +479,12 @@ discourse_ai:client: truevalidator: "DiscourseAi::Configuration::LlmDependencyValidator"area: "ai-features/translation"- ai_translation_model:+ ai_translation_model: # Deprecated. TODO(keegan): Remove 2025-09-01default: ""type: enumallow_any: falseenum: "DiscourseAi::Configuration::LlmEnumerator"- validator: "DiscourseAi::Configuration::LlmValidator"- area: "ai-features/translation"+ hidden: trueai_translation_locale_detector_persona:default: "-27"type: enumdiff --git a/plugins/discourse-ai/db/migrate/20250710173803_seed_ai_default_llm_model.rb b/plugins/discourse-ai/db/migrate/20250710173803_seed_ai_default_llm_model.rbnew file mode 100644index 00000000000..721c4ceca98--- /dev/null+++ b/plugins/discourse-ai/db/migrate/20250710173803_seed_ai_default_llm_model.rb@@ -0,0 +1,21 @@+# frozen_string_literal: true+class SeedAiDefaultLlmModel < ActiveRecord::Migration[7.2]+ def up+ return if DB.query_single("SELECT 1 FROM llm_models LIMIT 1").empty?++ last_model_id = DB.query_single("SELECT id FROM llm_models ORDER BY id DESC LIMIT 1").first++ if last_model_id.present?+ DB.exec(<<~SQL, llm_setting: "ai_default_llm_model", default: "#{last_model_id}")+ INSERT INTO site_settings(name, data_type, value, created_at, updated_at)+ VALUES (:llm_setting, 1, :default, NOW(), NOW())+ ON CONFLICT (name)+ DO NOTHING+ SQL+ end+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/plugins/discourse-ai/db/migrate/20250710180401_copy_ai_summarization_model_to_persona_default.rb b/plugins/discourse-ai/db/migrate/20250710180401_copy_ai_summarization_model_to_persona_default.rbnew file mode 100644index 00000000000..98c0bb7031a--- /dev/null+++ b/plugins/discourse-ai/db/migrate/20250710180401_copy_ai_summarization_model_to_persona_default.rb@@ -0,0 +1,33 @@+# frozen_string_literal: true+class CopyAiSummarizationModelToPersonaDefault < ActiveRecord::Migration[7.2]+ def up+ ai_summarization_model =+ DB.query_single("SELECT value FROM site_settings WHERE name = 'ai_summarization_model'").first++ if ai_summarization_model.present? && ai_summarization_model.start_with?("custom:")+ # Extract the model ID from the setting value (e.g., "custom:-5" -> "-5")+ model_id = ai_summarization_model.split(":").last++ persona_settings = %w[ai_summarization_persona ai_summary_gists_persona]+ default_persona_ids = [-11, -12]++ persona_ids_query =+ persona_settings+ .map { |setting| "SELECT value FROM site_settings WHERE name = '#{setting}'" }+ .join(" UNION ")+ persona_ids = DB.query_single(persona_ids_query).compact+ all_persona_ids = (default_persona_ids + persona_ids).map(&:to_i).uniq.join(",")++ # Update the summarization personas with the extracted model ID+ execute(<<~SQL)+ UPDATE ai_personas+ SET default_llm_id = #{model_id}+ WHERE id IN (#{all_persona_ids}) AND default_llm_id IS NULL+ SQL+ end+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/plugins/discourse-ai/db/migrate/20250710181656_copy_ai_helper_model_to_persona_default.rb b/plugins/discourse-ai/db/migrate/20250710181656_copy_ai_helper_model_to_persona_default.rbnew file mode 100644index 00000000000..996cfa746ef--- /dev/null+++ b/plugins/discourse-ai/db/migrate/20250710181656_copy_ai_helper_model_to_persona_default.rb@@ -0,0 +1,43 @@+# frozen_string_literal: true+class CopyAiHelperModelToPersonaDefault < ActiveRecord::Migration[7.2]+ def up+ ai_helper_model =+ DB.query_single("SELECT value FROM site_settings WHERE name = 'ai_helper_model'").first++ if ai_helper_model.present? && ai_helper_model.start_with?("custom:")+ # Extract the model ID from the setting value (e.g., "custom:1" -> "1")+ model_id = ai_helper_model.split(":").last++ # Get persona IDs from site settings+ persona_settings = %w[+ ai_helper_proofreader_persona+ ai_helper_title_suggestions_persona+ ai_helper_explain_persona+ ai_helper_smart_dates_persona+ ai_helper_translator_persona+ ai_helper_markdown_tables_persona+ ai_helper_custom_prompt_persona+ ]++ default_persona_ids = [-18, -19, -20, -22, -23, -24, -25]+ persona_ids_query =+ persona_settings+ .map { |setting| "SELECT value FROM site_settings WHERE name = '#{setting}'" }+ .join(" UNION ")+ persona_ids = DB.query_single(persona_ids_query).compact++ all_persona_ids = (default_persona_ids + persona_ids).map(&:to_i).uniq.join(",")++ # Update the helper personas with the extracted model ID+ execute(<<~SQL)+ UPDATE ai_personas+ SET default_llm_id = #{model_id}+ WHERE id IN (#{all_persona_ids}) AND default_llm_id IS NULL+ SQL+ end+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/plugins/discourse-ai/db/migrate/20250710215720_copy_hyde_model_to_persona.rb b/plugins/discourse-ai/db/migrate/20250710215720_copy_hyde_model_to_persona.rbnew file mode 100644index 00000000000..80c3f7d0479--- /dev/null+++ b/plugins/discourse-ai/db/migrate/20250710215720_copy_hyde_model_to_persona.rb@@ -0,0 +1,35 @@+# frozen_string_literal: true+class CopyHydeModelToPersona < ActiveRecord::Migration[7.2]+ def up+ hyde_model =+ DB.query_single(+ "SELECT value FROM site_settings WHERE name = 'ai_embeddings_semantic_search_hyde_model'",+ ).first++ if hyde_model.present? && hyde_model.start_with?("custom:")+ # Extract the model ID from the setting value (e.g., "custom:1" -> "1")+ model_id = hyde_model.split(":").last++ persona_settings = %w[ai_embeddings_semantic_search_hyde_persona]+ default_persona_ids = [-32]+ persona_ids_query =+ persona_settings+ .map { |setting| "SELECT value FROM site_settings WHERE name = '#{setting}'" }+ .join(" UNION ")+ persona_ids = DB.query_single(persona_ids_query).compact++ all_persona_ids = (default_persona_ids + persona_ids).map(&:to_i).uniq.join(",")++ # Update the hyde persona with the extracted model ID+ execute(<<~SQL)+ UPDATE ai_personas+ SET default_llm_id = #{model_id}+ WHERE id IN (#{all_persona_ids}) AND default_llm_id IS NULL+ SQL+ end+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/plugins/discourse-ai/db/migrate/20250716005451_copy_translation_model_to_persona.rb b/plugins/discourse-ai/db/migrate/20250716005451_copy_translation_model_to_persona.rbnew file mode 100644index 00000000000..aa1bb69ed98--- /dev/null+++ b/plugins/discourse-ai/db/migrate/20250716005451_copy_translation_model_to_persona.rb@@ -0,0 +1,39 @@+# frozen_string_literal: true+class CopyTranslationModelToPersona < ActiveRecord::Migration[7.2]+ def up+ ai_translation_model =+ DB.query_single("SELECT value FROM site_settings WHERE name = 'ai_translation_model'").first++ if ai_translation_model.present? && ai_translation_model.start_with?("custom:")+ # Extract the model ID from the setting value (e.g., "custom:-5" -> "-5")+ model_id = ai_translation_model.split(":").last++ persona_settings = %w[+ ai_translation_locale_detector_persona+ ai_translation_post_raw_translator_persona+ ai_translation_topic_title_translator_persona+ ai_translation_short_text_translator_persona+ ]+ default_persona_ids = [-27, -28, -29, -30]++ persona_ids_query =+ persona_settings+ .map { |setting| "SELECT value FROM site_settings WHERE name = '#{setting}'" }+ .join(" UNION ")+ persona_ids = DB.query_single(persona_ids_query).compact++ all_persona_ids = (default_persona_ids + persona_ids).map(&:to_i).uniq.join(",")++ # Update the translation personas (IDs -27, -28, -29, -30) with the extracted model ID+ execute(<<~SQL)+ UPDATE ai_personas+ SET default_llm_id = #{model_id}+ WHERE id IN (#{all_persona_ids}) AND default_llm_id IS NULL+ SQL+ end+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/plugins/discourse-ai/db/migrate/20250716005855_copy_ai_image_caption_model_to_persona_default.rb b/plugins/discourse-ai/db/migrate/20250716005855_copy_ai_image_caption_model_to_persona_default.rbnew file mode 100644index 00000000000..b2a02ab0ec9--- /dev/null+++ b/plugins/discourse-ai/db/migrate/20250716005855_copy_ai_image_caption_model_to_persona_default.rb@@ -0,0 +1,37 @@+# frozen_string_literal: true+class CopyAiImageCaptionModelToPersonaDefault < ActiveRecord::Migration[7.2]+ def up+ ai_helper_image_caption_model =+ DB.query_single(+ "SELECT value FROM site_settings WHERE name = 'ai_helper_image_caption_model'",+ ).first++ if ai_helper_image_caption_model.present? &&+ ai_helper_image_caption_model.start_with?("custom:")+ # Extract the model ID from the setting value (e.g., "custom:1" -> "1")+ model_id = ai_helper_image_caption_model.split(":").last++ persona_settings = %w[ai_helper_post_illustrator_persona ai_helper_image_caption_persona]+ default_persona_ids = [-21, -26]++ persona_ids_query =+ persona_settings+ .map { |setting| "SELECT value FROM site_settings WHERE name = '#{setting}'" }+ .join(" UNION ")+ persona_ids = DB.query_single(persona_ids_query).compact++ all_persona_ids = (default_persona_ids + persona_ids).map(&:to_i).uniq.join(",")++ # Update the helper personas with the extracted model ID+ execute(<<~SQL)+ UPDATE ai_personas+ SET default_llm_id = #{model_id}+ WHERE id IN (#{all_persona_ids}) AND default_llm_id IS NULL+ SQL+ end+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/plugins/discourse-ai/lib/ai_helper/assistant.rb b/plugins/discourse-ai/lib/ai_helper/assistant.rbindex be61e415a53..01a27675ea4 100644--- a/plugins/discourse-ai/lib/ai_helper/assistant.rb+++ b/plugins/discourse-ai/lib/ai_helper/assistant.rb@@ -312,18 +312,9 @@ module DiscourseAi# Priorities are:# 1. Persona's default LLM- # 2. Hidden `ai_helper_model` setting, or `ai_helper_image_caption_model` for image_caption.- # 3. Newest LLM config+ # 2. SiteSetting.ai_default_llm_id (or newest LLM if not set)def self.find_ai_helper_model(helper_mode, persona_klass)- model_id = persona_klass.default_llm_id-- if !model_id- if helper_mode == IMAGE_CAPTION- model_id = SiteSetting.ai_helper_image_caption_model&.split(":")&.last- else- model_id = SiteSetting.ai_helper_model&.split(":")&.last- end- end+ model_id = persona_klass.default_llm_id || SiteSetting.ai_default_llm_modelif model_id.present?LlmModel.find_by(id: model_id)diff --git a/plugins/discourse-ai/lib/ai_helper/chat_thread_titler.rb b/plugins/discourse-ai/lib/ai_helper/chat_thread_titler.rbindex 15ffc52ca84..73f559da4ae 100644--- a/plugins/discourse-ai/lib/ai_helper/chat_thread_titler.rb+++ b/plugins/discourse-ai/lib/ai_helper/chat_thread_titler.rb@@ -12,10 +12,14 @@ module DiscourseAireturn nil if content.blank?suggested_title = call_llm(content)+ return nil if suggested_title.blank?+cleanup(suggested_title)enddef call_llm(thread_content)+ return nil if SiteSetting.ai_default_llm_model.blank?+chat = "<input>\n#{thread_content}\n</input>"prompt =@@ -30,7 +34,7 @@ module DiscourseAimessages: [{ type: :user, content: chat, id: "User" }],)- DiscourseAi::Completions::Llm.proxy(SiteSetting.ai_helper_model).generate(+ DiscourseAi::Completions::Llm.proxy(SiteSetting.ai_default_llm_model).generate(prompt,user: Discourse.system_user,stop_sequences: ["</input>"],diff --git a/plugins/discourse-ai/lib/ai_helper/painter.rb b/plugins/discourse-ai/lib/ai_helper/painter.rbindex 9be8b95a0b1..8e3881c304a 100644--- a/plugins/discourse-ai/lib/ai_helper/painter.rb+++ b/plugins/discourse-ai/lib/ai_helper/painter.rb@@ -57,6 +57,12 @@ module DiscourseAienddef diffusion_prompt(text, user)+ llm_model =+ AiPersona.find_by(id: SiteSetting.ai_helper_post_illustrator_persona)&.default_llm_id ||+ SiteSetting.ai_default_llm_model++ return nil if llm_model.blank?+prompt =DiscourseAi::Completions::Prompt.new(<<~TEXT.strip,@@ -66,7 +72,7 @@ module DiscourseAimessages: [{ type: :user, content: text, id: user.username }],)- DiscourseAi::Completions::Llm.proxy(SiteSetting.ai_helper_model).generate(+ DiscourseAi::Completions::Llm.proxy(llm_model).generate(prompt,user: user,feature_name: "illustrate_post",diff --git a/plugins/discourse-ai/lib/automation.rb b/plugins/discourse-ai/lib/automation.rbindex 0410aed13f9..bd23b3bf75e 100644--- a/plugins/discourse-ai/lib/automation.rb+++ b/plugins/discourse-ai/lib/automation.rb@@ -26,20 +26,10 @@ module DiscourseAienddef self.available_models- values = DB.query_hash(<<~SQL)+ DB.query_hash(<<~SQL).each { |value_h| value_h["id"] = "#{value_h["id"]}" }SELECT display_name AS translated_name, id AS idFROM llm_modelsSQL-- values =- values- .filter do |value_h|- value_h["id"] > 0 ||- SiteSetting.ai_automation_allowed_seeded_models_map.include?(value_h["id"].to_s)- end- .each { |value_h| value_h["id"] = "custom:#{value_h["id"]}" }-- valuesenddef self.available_persona_choices(require_user: true, require_default_llm: true)diff --git a/plugins/discourse-ai/lib/automation/report_runner.rb b/plugins/discourse-ai/lib/automation/report_runner.rbindex 1c207a45a65..d4d06b143b4 100644--- a/plugins/discourse-ai/lib/automation/report_runner.rb+++ b/plugins/discourse-ai/lib/automation/report_runner.rb@@ -74,7 +74,7 @@ module DiscourseAielseI18n.t("discourse_automation.scriptables.llm_report.title")end- @model = LlmModel.find_by(id: model.split(":")&.last)+ @model = LlmModel.find_by(id: model)@persona = AiPersona.find(persona_id).class_instance.new@category_ids = category_ids@tags = tagsdiff --git a/plugins/discourse-ai/lib/completions/llm.rb b/plugins/discourse-ai/lib/completions/llm.rbindex 70e84004961..663c6e68c98 100644--- a/plugins/discourse-ai/lib/completions/llm.rb+++ b/plugins/discourse-ai/lib/completions/llm.rb@@ -292,6 +292,8 @@ module DiscourseAillm_model =if model.is_a?(LlmModel)model+ elsif model.is_a?(Numeric)+ LlmModel.find_by(id: model)elsemodel_name_without_prov = model.split(":").last.to_idiff --git a/plugins/discourse-ai/lib/configuration/feature.rb b/plugins/discourse-ai/lib/configuration/feature.rbindex ee62e8c360f..f250010c269 100644--- a/plugins/discourse-ai/lib/configuration/feature.rb+++ b/plugins/discourse-ai/lib/configuration/feature.rb@@ -263,8 +263,9 @@ module DiscourseAiDiscourseAi::Embeddings::SemanticSearch.new(nil).find_ai_hyde_model(persona_klass)end- if llm_model.blank? && persona.default_llm_id- llm_model = LlmModel.find_by(id: persona.default_llm_id)+ if llm_model.blank?+ llm_model_id = persona.default_llm_id || SiteSetting.ai_default_llm_model+ llm_model = LlmModel.find_by(id: llm_model_id)endllm_models << llm_model if llm_modeldiff --git a/plugins/discourse-ai/lib/configuration/llm_dependency_validator.rb b/plugins/discourse-ai/lib/configuration/llm_dependency_validator.rbindex 0cf715fe0c1..8ca890be099 100644--- a/plugins/discourse-ai/lib/configuration/llm_dependency_validator.rb+++ b/plugins/discourse-ai/lib/configuration/llm_dependency_validator.rb@@ -10,16 +10,9 @@ module DiscourseAidef valid_value?(val)return true if val == "f"- if @opts[:name] == :ai_summarization_enabled || @opts[:name] == :ai_helper_enabled- has_llms = LlmModel.count > 0- @no_llms_configured = !has_llms- has_llms- else- @llm_dependency_setting_name =- DiscourseAi::Configuration::LlmValidator.new.choose_llm_setting_for(@opts[:name])+ @llm_dependency_setting_name = :ai_default_llm_model- SiteSetting.public_send(@llm_dependency_setting_name).present?- end+ SiteSetting.public_send(@llm_dependency_setting_name).present?enddef error_messagediff --git a/plugins/discourse-ai/lib/configuration/llm_enumerator.rb b/plugins/discourse-ai/lib/configuration/llm_enumerator.rbindex 200fc0a2760..cd2c33d54ea 100644--- a/plugins/discourse-ai/lib/configuration/llm_enumerator.rb+++ b/plugins/discourse-ai/lib/configuration/llm_enumerator.rb@@ -22,24 +22,53 @@ module DiscourseAi.each { |llm_id, name, id| rval[llm_id] << { type: :ai_persona, name: name, id: id } }if SiteSetting.ai_helper_enabled- model_id = SiteSetting.ai_helper_model.split(":").last.to_i- rval[model_id] << { type: :ai_helper } if model_id != 0+ {+ "#{I18n.t("js.discourse_ai.features.ai_helper.proofread")}" =>+ SiteSetting.ai_helper_proofreader_persona,+ "#{I18n.t("js.discourse_ai.features.ai_helper.title_suggestions")}" =>+ SiteSetting.ai_helper_title_suggestions_persona,+ "#{I18n.t("js.discourse_ai.features.ai_helper.explain")}" =>+ SiteSetting.ai_helper_explain_persona,+ "#{I18n.t("js.discourse_ai.features.ai_helper.illustrate_post")}" =>+ SiteSetting.ai_helper_post_illustrator_persona,+ "#{I18n.t("js.discourse_ai.features.ai_helper.smart_dates")}" =>+ SiteSetting.ai_helper_smart_dates_persona,+ "#{I18n.t("js.discourse_ai.features.ai_helper.translator")}" =>+ SiteSetting.ai_helper_translator_persona,+ "#{I18n.t("js.discourse_ai.features.ai_helper.markdown_tables")}" =>+ SiteSetting.ai_helper_markdown_tables_persona,+ "#{I18n.t("js.discourse_ai.features.ai_helper.custom_prompt")}" =>+ SiteSetting.ai_helper_custom_prompt_persona,+ }.each do |helper_type, persona_id|+ next if persona_id.blank?++ persona = AiPersona.find_by(id: persona_id)+ next if persona.blank? || persona.default_llm_id.blank?++ model_id = persona.default_llm_id || SiteSetting.ai_default_llm_model.to_i+ rval[model_id] << { type: :ai_helper, name: helper_type }+ endend- if SiteSetting.ai_helper_image_caption_model- model_id = SiteSetting.ai_helper_image_caption_model.split(":").last.to_i- rval[model_id] << { type: :ai_helper_image_caption } if model_id != 0+ if SiteSetting.ai_helper_enabled_features.split("|").include?("image_caption")+ image_caption_persona = AiPersona.find_by(id: SiteSetting.ai_helper_image_caption_persona)+ model_id = image_caption_persona.default_llm_id || SiteSetting.ai_default_llm_model.to_i++ rval[model_id] << { type: :ai_helper_image_caption }endif SiteSetting.ai_summarization_enabledsummarization_persona = AiPersona.find_by(id: SiteSetting.ai_summarization_persona)- model_id = summarization_persona.default_llm_id || LlmModel.last&.id+ model_id = summarization_persona.default_llm_id || SiteSetting.ai_default_llm_model.to_irval[model_id] << { type: :ai_summarization }endif SiteSetting.ai_embeddings_semantic_search_enabled- model_id = SiteSetting.ai_embeddings_semantic_search_hyde_model.split(":").last.to_i+ search_persona =+ AiPersona.find_by(id: SiteSetting.ai_embeddings_semantic_search_hyde_persona)+ model_id = search_persona.default_llm_id || SiteSetting.ai_default_llm_model.to_i+rval[model_id] << { type: :ai_embeddings_semantic_search }end@@ -58,12 +87,8 @@ module DiscourseAi).each do |model_text, name, id|next if model_text.blank?- model_id = model_text.split("custom:").last.to_i- if model_id.present?- if model_text =~ /custom:(\d+)/- rval[model_id] << { type: :automation, name: name, id: id }- end- end+ model_id = model_text.to_i+ rval[model_id] << { type: :automation, name: name, id: id } if model_id.present?endend@@ -107,7 +132,6 @@ module DiscourseAiendend- values.each { |value_h| value_h[:value] = "custom:#{value_h[:value]}" }valuesendenddiff --git a/plugins/discourse-ai/lib/configuration/llm_validator.rb b/plugins/discourse-ai/lib/configuration/llm_validator.rbindex 36c3c63b1c0..ed56abea894 100644--- a/plugins/discourse-ai/lib/configuration/llm_validator.rb+++ b/plugins/discourse-ai/lib/configuration/llm_validator.rb@@ -2,9 +2,6 @@module DiscourseAimodule Configuration- class InvalidSeededModelError < StandardError- end-class LlmValidatordef initialize(opts = {})@opts = opts@@ -12,18 +9,21 @@ module DiscourseAidef valid_value?(val)if val == ""- @parent_module_name = modules_and_choose_llm_settings.invert[@opts[:name]]-- @parent_enabled = SiteSetting.public_send(@parent_module_name)- return !@parent_enabled+ if @opts[:name] == :ai_default_llm_model+ @parent_module_names = []++ enabled_settings.each do |setting_name|+ if SiteSetting.public_send(setting_name) == true+ @parent_module_names << setting_name+ @parent_enabled = true+ end+ end++ return !@parent_enabled+ endend- allowed_seeded_model?(val)-run_test(val).tap { |result| @unreachable = result }- rescue DiscourseAi::Configuration::InvalidSeededModelError => e- @unreachable = true- falserescue StandardError => eraise e if Rails.env.test?@unreachable = true@@ -37,55 +37,36 @@ module DiscourseAi.present?end- def modules_using(llm_model)- choose_llm_settings = modules_and_choose_llm_settings.values+ def is_using(llm_model)+ in_use_by = AiPersona.where(default_llm_id: llm_model.id).pluck(:name)++ in_use_by << "ai_default_llm_model" if SiteSetting.ai_default_llm_model.to_i == llm_model.id- choose_llm_settings.select { |s| SiteSetting.public_send(s) == "custom:#{llm_model.id}" }+ in_use_byenddef error_message- if @parent_enabled+ if @parent_enabled && @parent_module_names.present?return(I18n.t(- "discourse_ai.llm.configuration.disable_module_first",- setting: @parent_module_name,+ "discourse_ai.llm.configuration.disable_modules_first",+ settings: @parent_module_names.join(", "),))end- if @invalid_seeded_model- return I18n.t("discourse_ai.llm.configuration.invalid_seeded_model")- end-return unless @unreachableI18n.t("discourse_ai.llm.configuration.model_unreachable")end- def choose_llm_setting_for(module_enabler_setting)- modules_and_choose_llm_settings[module_enabler_setting]- end-- def modules_and_choose_llm_settings- {- ai_embeddings_semantic_search_enabled: :ai_embeddings_semantic_search_hyde_model,- ai_helper_enabled: :ai_helper_model,- ai_summarization_enabled: :ai_summarization_model,- ai_translation_enabled: :ai_translation_model,- }- end-- def allowed_seeded_model?(val)- id = val.split(":").last- return true if id.to_i > 0-- setting = @opts[:name]- allowed_list = SiteSetting.public_send("#{setting}_allowed_seeded_models")-- if allowed_list.split("|").exclude?(id)- @invalid_seeded_model = true- raise DiscourseAi::Configuration::InvalidSeededModelError.new- end+ def enabled_settings+ %i[+ ai_embeddings_semantic_search_enabled+ ai_helper_enabled+ ai_summarization_enabled+ ai_translation_enabled+ ]endendenddiff --git a/plugins/discourse-ai/lib/configuration/llm_vision_enumerator.rb b/plugins/discourse-ai/lib/configuration/llm_vision_enumerator.rbindex c4cf1a621ac..0ef16b70544 100644--- a/plugins/discourse-ai/lib/configuration/llm_vision_enumerator.rb+++ b/plugins/discourse-ai/lib/configuration/llm_vision_enumerator.rb@@ -16,8 +16,6 @@ module DiscourseAiWHERE vision_enabledSQL- values.each { |value_h| value_h[:value] = "custom:#{value_h[:value]}" }-valuesendenddiff --git a/plugins/discourse-ai/lib/configuration/simple_llm_validator.rb b/plugins/discourse-ai/lib/configuration/simple_llm_validator.rbnew file mode 100644index 00000000000..301ac4ad049--- /dev/null+++ b/plugins/discourse-ai/lib/configuration/simple_llm_validator.rb@@ -0,0 +1,39 @@+# frozen_string_literal: true++module DiscourseAi+ module Configuration+ class SimpleLlmValidator+ def initialize(opts = {})+ @opts = opts+ end++ def valid_value?(val)+ return true if val == ""++ run_test(val).tap { |result| @unreachable = result }+ rescue StandardError => e+ raise e if Rails.env.test?+ @unreachable = true+ true+ end++ def run_test(val)+ if Rails.env.test?+ # In test mode, we assume the model is reachable.+ return true+ end++ DiscourseAi::Completions::Llm+ .proxy(val)+ .generate("How much is 1 + 1?", user: nil, feature_name: "llm_validator")+ .present?+ end++ def error_message+ return unless @unreachable++ I18n.t("discourse_ai.llm.configuration.model_unreachable")+ end+ end+ end+enddiff --git a/plugins/discourse-ai/lib/embeddings/semantic_search.rb b/plugins/discourse-ai/lib/embeddings/semantic_search.rbindex 726f203dc4a..6d44c1f7356 100644--- a/plugins/discourse-ai/lib/embeddings/semantic_search.rb+++ b/plugins/discourse-ai/lib/embeddings/semantic_search.rb@@ -6,8 +6,8 @@ module DiscourseAidef self.clear_cache_for(query)digest = OpenSSL::Digest::SHA1.hexdigest(query)- hyde_key =- "semantic-search-#{digest}-#{SiteSetting.ai_embeddings_semantic_search_hyde_model}"+ hyde_model_id = find_ai_hyde_model_id+ hyde_key = "semantic-search-#{digest}-#{hyde_model_id}"Discourse.cache.delete(hyde_key)Discourse.cache.delete("#{hyde_key}-#{SiteSetting.ai_embeddings_selected_model}")@@ -20,12 +20,9 @@ module DiscourseAidef cached_query?(query)digest = OpenSSL::Digest::SHA1.hexdigest(query)+ hyde_model_id = self.class.find_ai_hyde_model_idembedding_key =- build_embedding_key(- digest,- SiteSetting.ai_embeddings_semantic_search_hyde_model,- SiteSetting.ai_embeddings_selected_model,- )+ build_embedding_key(digest, hyde_model_id, SiteSetting.ai_embeddings_selected_model)Discourse.cache.read(embedding_key).present?end@@ -36,14 +33,11 @@ module DiscourseAidef hyde_embedding(search_term)digest = OpenSSL::Digest::SHA1.hexdigest(search_term)- hyde_key = build_hyde_key(digest, SiteSetting.ai_embeddings_semantic_search_hyde_model)+ hyde_model_id = self.class.find_ai_hyde_model_id+ hyde_key = build_hyde_key(digest, hyde_model_id)embedding_key =- build_embedding_key(- digest,- SiteSetting.ai_embeddings_semantic_search_hyde_model,- SiteSetting.ai_embeddings_selected_model,- )+ build_embedding_key(digest, hyde_model_id, SiteSetting.ai_embeddings_selected_model)hypothetical_post =Discourse@@ -111,6 +105,7 @@ module DiscourseAimax_semantic_results_per_page = 100search = Search.new(query, { guardian: guardian })search_term = search.term+ hyde_model_id = self.class.find_ai_hyde_model_idreturn [] if search_term.nil? || search_term.length < SiteSetting.min_search_term_length@@ -119,11 +114,7 @@ module DiscourseAidigest = OpenSSL::Digest::SHA1.hexdigest(search_term)embedding_key =- build_embedding_key(- digest,- SiteSetting.ai_embeddings_semantic_search_hyde_model,- SiteSetting.ai_embeddings_selected_model,- )+ build_embedding_key(digest, hyde_model_id, SiteSetting.ai_embeddings_selected_model)search_term_embedding =Discourse@@ -210,15 +201,28 @@ module DiscourseAi# Priorities are:# 1. Persona's default LLM- # 2. `ai_embeddings_semantic_search_hyde_model` setting.+ # 2. SiteSetting.ai_default_llm_id (or newest LLM if not set)def find_ai_hyde_model(persona_klass)- model_id =- persona_klass.default_llm_id ||- SiteSetting.ai_embeddings_semantic_search_hyde_model&.split(":")&.last+ model_id = persona_klass.default_llm_id || SiteSetting.ai_default_llm_model- return if model_id.blank?+ if model_id.present?+ LlmModel.find_by(id: model_id)+ else+ LlmModel.last+ end+ end++ def self.find_ai_hyde_model_id+ persona_llm_id =+ AiPersona.find_by(+ id: SiteSetting.ai_embeddings_semantic_search_hyde_persona,+ )&.default_llm_id- LlmModel.find_by(id: model_id)+ if persona_llm_id.present?+ persona_llm_id+ else+ SiteSetting.ai_default_llm_model.to_i || LlmModel.last&.id+ endendprivatediff --git a/plugins/discourse-ai/lib/summarization.rb b/plugins/discourse-ai/lib/summarization.rbindex a7b697638cb..f8f71cab2da 100644--- a/plugins/discourse-ai/lib/summarization.rb+++ b/plugins/discourse-ai/lib/summarization.rb@@ -54,11 +54,9 @@ module DiscourseAi# Priorities are:# 1. Persona's default LLM- # 2. Hidden `ai_summarization_model` setting- # 3. Newest LLM config+ # 2. SiteSetting.ai_default_llm_id (or newest LLM if not set)def find_summarization_model(persona_klass)- model_id =- persona_klass.default_llm_id || SiteSetting.ai_summarization_model&.split(":")&.last # Remove legacy custom provider.+ model_id = persona_klass.default_llm_id || SiteSetting.ai_default_llm_modelif model_id.present?LlmModel.find_by(id: model_id)@@ -73,7 +71,7 @@ module DiscourseAipersona = persona_klass.newuser = User.find_by(id: persona_klass.user_id) || Discourse.system_user- bot = DiscourseAi::Personas::Bot.as(user, persona: persona, model: llm_model)+ DiscourseAi::Personas::Bot.as(user, persona: persona, model: llm_model)endendenddiff --git a/plugins/discourse-ai/lib/tasks/create_topics.rake b/plugins/discourse-ai/lib/tasks/create_topics.rakeindex 3095345bb8d..f64953e5b2e 100644--- a/plugins/discourse-ai/lib/tasks/create_topics.rake+++ b/plugins/discourse-ai/lib/tasks/create_topics.rake@@ -88,7 +88,7 @@ namespace :ai domessages: [{ type: :user, content: prompt, id: "user" }],)- DiscourseAi::Completions::Llm.proxy(SiteSetting.ai_helper_model).generate(+ DiscourseAi::Completions::Llm.proxy(SiteSetting.ai_defaulit_llm_model).generate(prompt,user: Discourse.system_user,feature_name: "topic-generator",diff --git a/plugins/discourse-ai/lib/translation.rb b/plugins/discourse-ai/lib/translation.rbindex 09093f1c3c3..cfad97e541b 100644--- a/plugins/discourse-ai/lib/translation.rb+++ b/plugins/discourse-ai/lib/translation.rb@@ -3,11 +3,28 @@module DiscourseAimodule Translationdef self.enabled?- SiteSetting.discourse_ai_enabled && SiteSetting.ai_translation_enabled &&- SiteSetting.ai_translation_model.present? &&+ SiteSetting.discourse_ai_enabled && SiteSetting.ai_translation_enabled && has_llm_model? &&SiteSetting.content_localization_supported_locales.present?end+ def self.has_llm_model?+ persona_ids = [+ SiteSetting.ai_translation_locale_detector_persona,+ SiteSetting.ai_translation_post_raw_translator_persona,+ SiteSetting.ai_translation_topic_title_translator_persona,+ SiteSetting.ai_translation_short_text_translator_persona,+ ]++ persona_default_llms = AiPersona.where(id: persona_ids).pluck(:default_llm_id)+ default_llm_model = SiteSetting.ai_default_llm_model++ if persona_default_llms.any?(&:blank?) && default_llm_model.blank?+ false+ else+ true+ end+ end+def self.backfill_enabled?enabled? && SiteSetting.ai_translation_backfill_hourly_rate > 0 &&SiteSetting.ai_translation_backfill_max_age_days > 0diff --git a/plugins/discourse-ai/lib/translation/base_translator.rb b/plugins/discourse-ai/lib/translation/base_translator.rbindex 2ee3fb80e35..1d15892abae 100644--- a/plugins/discourse-ai/lib/translation/base_translator.rb+++ b/plugins/discourse-ai/lib/translation/base_translator.rb@@ -69,9 +69,13 @@ module DiscourseAienddef self.preferred_llm_model(persona_klass)- id = persona_klass.default_llm_id || SiteSetting.ai_translation_model&.split(":")&.last- return nil if id.blank?- LlmModel.find_by(id:)+ model_id = persona_klass.default_llm_id || SiteSetting.ai_default_llm_model++ if model_id.present?+ LlmModel.find_by(id: model_id)+ else+ LlmModel.last+ endendendenddiff --git a/plugins/discourse-ai/spec/configuration/feature_spec.rb b/plugins/discourse-ai/spec/configuration/feature_spec.rbindex 5f7f0d9f9f7..c01cdf39916 100644--- a/plugins/discourse-ai/spec/configuration/feature_spec.rb+++ b/plugins/discourse-ai/spec/configuration/feature_spec.rb@@ -4,6 +4,8 @@ RSpec.describe DiscourseAi::Configuration::Feature dofab!(:llm_model)fab!(:ai_persona) { Fabricate(:ai_persona, default_llm_id: llm_model.id) }+ before { assign_fake_provider_to(:ai_default_llm_model) }+def allow_configuring_setting(&block)DiscourseAi::Completions::Llm.with_prepared_responses(["OK"]) { block.call }end@@ -38,7 +40,6 @@ RSpec.describe DiscourseAi::Configuration::Feature doit "returns the configured llm model" doSiteSetting.ai_summarization_persona = ai_persona.id- allow_configuring_setting { SiteSetting.ai_summarization_model = "custom:#{llm_model.id}" }expect(ai_feature.llm_models).to eq([llm_model])endend@@ -55,8 +56,6 @@ RSpec.describe DiscourseAi::Configuration::Feature doit "returns the persona's default llm when no specific helper model is set" doSiteSetting.ai_helper_proofreader_persona = ai_persona.id- SiteSetting.ai_helper_model = ""-expect(ai_feature.llm_models).to eq([llm_model])endend@@ -75,11 +74,7 @@ RSpec.describe DiscourseAi::Configuration::Feature doit "uses translation model when configured" doSiteSetting.ai_translation_locale_detector_persona = ai_persona.id- ai_persona.update!(default_llm_id: nil)- allow_configuring_setting do- SiteSetting.ai_translation_model = "custom:#{translation_model.id}"- end-+ ai_persona.update!(default_llm_id: translation_model.id)expect(ai_feature.llm_models).to eq([translation_model])endenddiff --git a/plugins/discourse-ai/spec/configuration/llm_enumerator_spec.rb b/plugins/discourse-ai/spec/configuration/llm_enumerator_spec.rbindex 7eea717fc53..c60996c9c63 100644--- a/plugins/discourse-ai/spec/configuration/llm_enumerator_spec.rb+++ b/plugins/discourse-ai/spec/configuration/llm_enumerator_spec.rb@@ -2,6 +2,7 @@RSpec.describe DiscourseAi::Configuration::LlmEnumerator dofab!(:fake_model)+ fab!(:ai_persona) { Fabricate(:ai_persona, default_llm_id: fake_model.id) }fab!(:llm_model)fab!(:seeded_model)fab!(:automation) do@@ -43,9 +44,16 @@ RSpec.describe DiscourseAi::Configuration::LlmEnumerator dodescribe "#global_usage" doit "returns a hash of Llm models in use globally" do- SiteSetting.ai_helper_model = "custom:#{fake_model.id}"+ assign_fake_provider_to(:ai_default_llm_model)+ SiteSetting.ai_helper_proofreader_persona = ai_persona.idSiteSetting.ai_helper_enabled = true- expect(described_class.global_usage).to eq(fake_model.id => [{ type: :ai_helper }])+ expect(described_class.global_usage).to eq(+ fake_model.id => [{ type: :ai_helper }],+ fake_model.id => [+ { id: ai_persona.id, name: ai_persona.name, type: :ai_persona },+ { name: "Proofread text", type: :ai_helper },+ ],+ )endit "returns information about automation rules" do@@ -53,7 +61,7 @@ RSpec.describe DiscourseAi::Configuration::LlmEnumerator docomponent: "text",name: "model",metadata: {- value: "custom:#{fake_model.id}",+ value: llm_model.id,},target: "script",)@@ -61,7 +69,8 @@ RSpec.describe DiscourseAi::Configuration::LlmEnumerator dousage = described_class.global_usageexpect(usage).to eq(- { fake_model.id => [{ type: :automation, name: "some automation", id: automation.id }] },+ fake_model.id => [{ id: ai_persona.id, name: ai_persona.name, type: :ai_persona }],+ llm_model.id => [{ id: automation.id, name: automation.name, type: :automation }],)endenddiff --git a/plugins/discourse-ai/spec/configuration/llm_validator_spec.rb b/plugins/discourse-ai/spec/configuration/llm_validator_spec.rbindex 89c73c57ce8..6825ac04e13 100644--- a/plugins/discourse-ai/spec/configuration/llm_validator_spec.rb+++ b/plugins/discourse-ai/spec/configuration/llm_validator_spec.rb@@ -4,19 +4,40 @@ RSpec.describe DiscourseAi::Configuration::LlmValidator dobefore { enable_current_plugin }describe "#valid_value?" do- context "when the parent module is enabled and we try to reset the selected model" do- before do- assign_fake_provider_to(:ai_summarization_model)- SiteSetting.ai_summarization_enabled = true- end+ let(:validator) { described_class.new(name: :ai_default_llm_model) }+ fab!(:llm_model)++ before do+ assign_fake_provider_to(:ai_default_llm_model)+ SiteSetting.ai_helper_enabled = false+ SiteSetting.ai_summarization_enabled = false+ SiteSetting.ai_embeddings_semantic_search_enabled = false+ SiteSetting.ai_translation_enabled = false+ end++ it "returns true when no modules are enabled and value is empty string" do+ expect(validator.valid_value?("")).to eq(true)+ end++ it "returns false when a module is enabled and value is empty string" do+ SiteSetting.ai_helper_enabled = true+ expect(validator.valid_value?("")).to eq(false)+ expect(validator.error_message).to include("ai_helper_enabled")+ end- it "returns false and displays an error message" do- validator = described_class.new(name: :ai_summarization_model)+ it "returns false when multiple modules are enabled and value is empty string" do+ SiteSetting.ai_helper_enabled = true+ SiteSetting.ai_summarization_enabled = true+ expect(validator.valid_value?("")).to eq(false)+ expect(validator.error_message).to include("ai_helper_enabled, ai_summarization_enabled")+ end- value = validator.valid_value?("")+ it "returns true for non-empty values regardless of module state" do+ SiteSetting.ai_helper_enabled = true+ SiteSetting.ai_summarization_enabled = true- expect(value).to eq(false)- expect(validator.error_message).to include("ai_summarization_enabled")+ DiscourseAi::Completions::Llm.with_prepared_responses([true]) do+ expect(validator.valid_value?(llm_model)).to eq(true)endendenddiff --git a/plugins/discourse-ai/spec/jobs/regular/detect_translate_post_spec.rb b/plugins/discourse-ai/spec/jobs/regular/detect_translate_post_spec.rbindex 6dc60ba71b5..ffb08aea9c4 100644--- a/plugins/discourse-ai/spec/jobs/regular/detect_translate_post_spec.rb+++ b/plugins/discourse-ai/spec/jobs/regular/detect_translate_post_spec.rb@@ -7,10 +7,8 @@ describe Jobs::DetectTranslatePost dolet(:locales) { %w[en ja] }before do+ assign_fake_provider_to(:ai_default_llm_model)enable_current_plugin- Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")- endSiteSetting.ai_translation_enabled = trueSiteSetting.content_localization_supported_locales = locales.join("|")enddiff --git a/plugins/discourse-ai/spec/jobs/regular/detect_translate_topic_spec.rb b/plugins/discourse-ai/spec/jobs/regular/detect_translate_topic_spec.rbindex e867c9e0d26..0bd4f3d3ba2 100644--- a/plugins/discourse-ai/spec/jobs/regular/detect_translate_topic_spec.rb+++ b/plugins/discourse-ai/spec/jobs/regular/detect_translate_topic_spec.rb@@ -7,10 +7,8 @@ describe Jobs::DetectTranslateTopic dolet(:locales) { %w[en ja] }before do+ assign_fake_provider_to(:ai_default_llm_model)enable_current_plugin- Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")- endSiteSetting.ai_translation_enabled = trueSiteSetting.content_localization_supported_locales = locales.join("|")enddiff --git a/plugins/discourse-ai/spec/jobs/regular/fast_track_topic_gist_spec.rb b/plugins/discourse-ai/spec/jobs/regular/fast_track_topic_gist_spec.rbindex 55745fa3e13..faba523b59f 100644--- a/plugins/discourse-ai/spec/jobs/regular/fast_track_topic_gist_spec.rb+++ b/plugins/discourse-ai/spec/jobs/regular/fast_track_topic_gist_spec.rb@@ -10,7 +10,7 @@ RSpec.describe Jobs::FastTrackTopicGist dobefore doenable_current_plugin- assign_fake_provider_to(:ai_summarization_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_summarization_enabled = trueSiteSetting.ai_summary_gists_enabled = trueenddiff --git a/plugins/discourse-ai/spec/jobs/regular/localize_categories_spec.rb b/plugins/discourse-ai/spec/jobs/regular/localize_categories_spec.rbindex f0d5e886925..34726801648 100644--- a/plugins/discourse-ai/spec/jobs/regular/localize_categories_spec.rb+++ b/plugins/discourse-ai/spec/jobs/regular/localize_categories_spec.rb@@ -10,10 +10,8 @@ describe Jobs::LocalizeCategories doendbefore do+ assign_fake_provider_to(:ai_default_llm_model)enable_current_plugin- Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")- endSiteSetting.ai_translation_enabled = trueSiteSetting.content_localization_supported_locales = "pt_BR|zh_CN"diff --git a/plugins/discourse-ai/spec/jobs/regular/localize_posts_spec.rb b/plugins/discourse-ai/spec/jobs/regular/localize_posts_spec.rbindex 8c54839c403..f2815e27b25 100644--- a/plugins/discourse-ai/spec/jobs/regular/localize_posts_spec.rb+++ b/plugins/discourse-ai/spec/jobs/regular/localize_posts_spec.rb@@ -7,10 +7,8 @@ describe Jobs::LocalizePosts dolet(:locales) { %w[en ja de] }before do+ assign_fake_provider_to(:ai_default_llm_model)enable_current_plugin- Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")- endSiteSetting.ai_translation_enabled = trueSiteSetting.content_localization_supported_locales = locales.join("|")SiteSetting.ai_translation_backfill_hourly_rate = 100diff --git a/plugins/discourse-ai/spec/jobs/regular/localize_topics_spec.rb b/plugins/discourse-ai/spec/jobs/regular/localize_topics_spec.rbindex d2f34add7ff..1f2fe0d35bf 100644--- a/plugins/discourse-ai/spec/jobs/regular/localize_topics_spec.rb+++ b/plugins/discourse-ai/spec/jobs/regular/localize_topics_spec.rb@@ -7,10 +7,8 @@ describe Jobs::LocalizeTopics dolet(:locales) { %w[en ja de] }before do+ assign_fake_provider_to(:ai_default_llm_model)enable_current_plugin- Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")- endSiteSetting.ai_translation_enabled = trueSiteSetting.content_localization_supported_locales = locales.join("|")SiteSetting.ai_translation_backfill_hourly_rate = 100diff --git a/plugins/discourse-ai/spec/jobs/regular/stream_composer_helper_spec.rb b/plugins/discourse-ai/spec/jobs/regular/stream_composer_helper_spec.rbindex e322254c56d..9ee821fa412 100644--- a/plugins/discourse-ai/spec/jobs/regular/stream_composer_helper_spec.rb+++ b/plugins/discourse-ai/spec/jobs/regular/stream_composer_helper_spec.rb@@ -5,7 +5,7 @@ RSpec.describe Jobs::StreamComposerHelper dobefore doenable_current_plugin- assign_fake_provider_to(:ai_helper_model)+ assign_fake_provider_to(:ai_default_llm_model)enddescribe "#execute" dodiff --git a/plugins/discourse-ai/spec/jobs/regular/stream_post_helper_spec.rb b/plugins/discourse-ai/spec/jobs/regular/stream_post_helper_spec.rbindex 80b84890de5..7a7442660b4 100644--- a/plugins/discourse-ai/spec/jobs/regular/stream_post_helper_spec.rb+++ b/plugins/discourse-ai/spec/jobs/regular/stream_post_helper_spec.rb@@ -5,7 +5,7 @@ RSpec.describe Jobs::StreamPostHelper dobefore doenable_current_plugin- assign_fake_provider_to(:ai_helper_model)+ assign_fake_provider_to(:ai_default_llm_model)enddescribe "#execute" dodiff --git a/plugins/discourse-ai/spec/jobs/regular/stream_topic_ai_summary_spec.rb b/plugins/discourse-ai/spec/jobs/regular/stream_topic_ai_summary_spec.rbindex f290af29dd6..20a829b67dc 100644--- a/plugins/discourse-ai/spec/jobs/regular/stream_topic_ai_summary_spec.rb+++ b/plugins/discourse-ai/spec/jobs/regular/stream_topic_ai_summary_spec.rb@@ -13,7 +13,7 @@ RSpec.describe Jobs::StreamTopicAiSummary dobefore doGroup.find(Group::AUTO_GROUPS[:trust_level_3]).add(user)- assign_fake_provider_to(:ai_summarization_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_summarization_enabled = trueenddiff --git a/plugins/discourse-ai/spec/jobs/scheduled/categories_locale_detection_backfill_spec.rb b/plugins/discourse-ai/spec/jobs/scheduled/categories_locale_detection_backfill_spec.rbindex 6fc1f56a9d9..3870c4a5750 100644--- a/plugins/discourse-ai/spec/jobs/scheduled/categories_locale_detection_backfill_spec.rb+++ b/plugins/discourse-ai/spec/jobs/scheduled/categories_locale_detection_backfill_spec.rb@@ -5,10 +5,8 @@ describe Jobs::CategoriesLocaleDetectionBackfill dosubject(:job) { described_class.new }before do+ assign_fake_provider_to(:ai_default_llm_model)enable_current_plugin- Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")- endSiteSetting.ai_translation_enabled = trueSiteSetting.ai_translation_backfill_hourly_rate = 100SiteSetting.content_localization_supported_locales = "en"diff --git a/plugins/discourse-ai/spec/jobs/scheduled/post_localization_backfill_spec.rb b/plugins/discourse-ai/spec/jobs/scheduled/post_localization_backfill_spec.rbindex 7a21cc1f99c..af25f50617c 100644--- a/plugins/discourse-ai/spec/jobs/scheduled/post_localization_backfill_spec.rb+++ b/plugins/discourse-ai/spec/jobs/scheduled/post_localization_backfill_spec.rb@@ -3,11 +3,9 @@describe Jobs::PostLocalizationBackfill dobefore doenable_current_plugin+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_translation_backfill_hourly_rate = 100SiteSetting.content_localization_supported_locales = "en"- Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")- endSiteSetting.ai_translation_enabled = trueenddiff --git a/plugins/discourse-ai/spec/jobs/scheduled/posts_locale_detection_backfill_spec.rb b/plugins/discourse-ai/spec/jobs/scheduled/posts_locale_detection_backfill_spec.rbindex 926fa461d6b..d5cf6a23f3f 100644--- a/plugins/discourse-ai/spec/jobs/scheduled/posts_locale_detection_backfill_spec.rb+++ b/plugins/discourse-ai/spec/jobs/scheduled/posts_locale_detection_backfill_spec.rb@@ -5,10 +5,8 @@ describe Jobs::PostsLocaleDetectionBackfill dosubject(:job) { described_class.new }before do+ assign_fake_provider_to(:ai_default_llm_model)enable_current_plugin- Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")- endSiteSetting.ai_translation_enabled = trueSiteSetting.ai_translation_backfill_hourly_rate = 100SiteSetting.content_localization_supported_locales = "en"diff --git a/plugins/discourse-ai/spec/jobs/scheduled/summaries_backfill_spec.rb b/plugins/discourse-ai/spec/jobs/scheduled/summaries_backfill_spec.rbindex 692aa630eb1..5d35aa8cb58 100644--- a/plugins/discourse-ai/spec/jobs/scheduled/summaries_backfill_spec.rb+++ b/plugins/discourse-ai/spec/jobs/scheduled/summaries_backfill_spec.rb@@ -11,7 +11,7 @@ RSpec.describe Jobs::SummariesBackfill dobefore doenable_current_plugin- assign_fake_provider_to(:ai_summarization_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_summarization_enabled = trueSiteSetting.ai_summary_backfill_maximum_topics_per_hour = limitSiteSetting.ai_summary_gists_enabled = truediff --git a/plugins/discourse-ai/spec/jobs/scheduled/topics_locale_detection_backfill_spec.rb b/plugins/discourse-ai/spec/jobs/scheduled/topics_locale_detection_backfill_spec.rbindex 88f27217e4f..4235689fa1a 100644--- a/plugins/discourse-ai/spec/jobs/scheduled/topics_locale_detection_backfill_spec.rb+++ b/plugins/discourse-ai/spec/jobs/scheduled/topics_locale_detection_backfill_spec.rb@@ -5,10 +5,8 @@ describe Jobs::TopicsLocaleDetectionBackfill dosubject(:job) { described_class.new }before do+ assign_fake_provider_to(:ai_default_llm_model)enable_current_plugin- Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")- endSiteSetting.ai_translation_enabled = trueSiteSetting.ai_translation_backfill_hourly_rate = 100SiteSetting.content_localization_supported_locales = "en"diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/anthropic_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/anthropic_spec.rbindex a454fcf2afe..ca0a01b0af2 100644--- a/plugins/discourse-ai/spec/lib/completions/endpoints/anthropic_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/anthropic_spec.rb@@ -4,7 +4,7 @@ require_relative "endpoint_compliance"RSpec.describe DiscourseAi::Completions::Endpoints::Anthropic dolet(:url) { "https://api.anthropic.com/v1/messages" }fab!(:model) { Fabricate(:anthropic_model, name: "claude-3-opus", vision_enabled: true) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(model) }let(:image100x100) { plugin_file_from_fixtures("100x100.jpg") }let(:upload100x100) doUploadCreator.new(image100x100, "image.jpg").create_for(Discourse.system_user.id)@@ -376,7 +376,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Anthropic domodel.provider_params["reasoning_tokens"] = 10_000model.save!- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(model)result = proxy.generate(prompt, user: Discourse.system_user)expect(result).to eq("Hello!")@@ -434,7 +434,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Anthropic do},).to_return(status: 200, body: body)- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(model)result = proxy.generate(prompt, user: Discourse.system_user)expect(result).to eq("Hello!")diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/aws_bedrock_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/aws_bedrock_spec.rbindex d75c8d5d76a..8d95be58183 100644--- a/plugins/discourse-ai/spec/lib/completions/endpoints/aws_bedrock_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/aws_bedrock_spec.rb@@ -49,7 +49,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock domodel.provider_params["disable_native_tools"] = truemodel.save!- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(model)incomplete_tool_call = <<~XML.strip<thinking>I should be ignored</thinking>@@ -124,7 +124,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock doendit "supports streaming function calls" do- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(model)request = nil@@ -295,7 +295,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock dodescribe "Claude 3 support" doit "supports regular completions" do- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(model)request = nil@@ -342,7 +342,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock domodel.provider_params["reasoning_tokens"] = 10_000model.save!- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(model)request = nil@@ -389,7 +389,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock doendit "supports claude 3 streaming" do- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(model)request = nil@@ -450,7 +450,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do},)- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(model)request = nilcontent = {@@ -489,7 +489,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock dodescribe "disabled tool use" doit "handles tool_choice: :none by adding a prefill message instead of using tool_choice param" do- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(model)request = nil# Create a prompt with tool_choice: :none@@ -551,7 +551,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock dodescribe "forced tool use" doit "can properly force tool use" do- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(model)request = niltools = [@@ -642,7 +642,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do{ type: "message_delta", delta: { usage: { output_tokens: 25 } } },].map { |message| encode_message(message) }- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(model)request = nilbedrock_mock.with_chunk_array_support dostub_request(@@ -720,7 +720,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do{ type: "message_delta", delta: { usage: { output_tokens: 25 } } },].map { |message| encode_message(message) }- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(model)request = nilbedrock_mock.with_chunk_array_support dostub_request(diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/cohere_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/cohere_spec.rbindex 43e8ec6153f..76f3e8fd20a 100644--- a/plugins/discourse-ai/spec/lib/completions/endpoints/cohere_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/cohere_spec.rb@@ -3,7 +3,7 @@ require_relative "endpoint_compliance"RSpec.describe DiscourseAi::Completions::Endpoints::Cohere dofab!(:cohere_model)- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{cohere_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(cohere_model) }fab!(:user)let(:prompt) dodiff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/gemini_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/gemini_spec.rbindex 2496acb5ffb..0c07cd3fb48 100644--- a/plugins/discourse-ai/spec/lib/completions/endpoints/gemini_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/gemini_spec.rb@@ -162,7 +162,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini doreq_body = nil- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)url = "#{model.url}:generateContent?key=123"stub_request(:post, url).with(@@ -188,7 +188,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini doreq_body = nil- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)url = "#{model.url}:generateContent?key=123"stub_request(:post, url).with(@@ -222,7 +222,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini doreq_body = nil- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)url = "#{model.url}:generateContent?key=123"stub_request(:post, url).with(@@ -248,7 +248,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini doreq_body = nil- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)url = "#{model.url}:generateContent?key=123"stub_request(:post, url).with(@@ -276,7 +276,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini doreq_body = nil- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)url = "#{model.url}:generateContent?key=123"stub_request(:post, url).with(@@ -299,7 +299,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini doit "properly encodes tool calls" doprompt = DiscourseAi::Completions::Prompt.new("Hello", tools: [echo_tool])- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)url = "#{model.url}:generateContent?key=123"response_json = { "functionCall" => { name: "echo", args: { text: "<S>ydney" } } }@@ -334,7 +334,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini doreq_body = nil- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)url = "#{model.url}:generateContent?key=123"stub_request(:post, url).with(@@ -412,7 +412,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini dopayload = rows.map { |r| "data: #{r.to_json}\n\n" }.join- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)url = "#{model.url}:streamGenerateContent?alt=sse&key=123"prompt = DiscourseAi::Completions::Prompt.new("Hello", tools: [echo_tool])@@ -452,7 +452,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini doTEXT- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)url = "#{model.url}:streamGenerateContent?alt=sse&key=123"output = []@@ -480,7 +480,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini dosplit = data.split("|")- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)url = "#{model.url}:streamGenerateContent?alt=sse&key=123"output = []@@ -499,7 +499,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini doreq_body = nil- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)url = "#{model.url}:generateContent?key=123"stub_request(:post, url).with(@@ -527,7 +527,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini doreq_body = nil- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)url = "#{model.url}:generateContent?key=123"stub_request(:post, url).with(@@ -602,7 +602,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini doreq_body = nil- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)url = "#{model.url}:streamGenerateContent?alt=sse&key=123"stub_request(:post, url).with(@@ -659,7 +659,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Gemini doTEXT- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)url = "#{model.url}:streamGenerateContent?alt=sse&key=123"output = []diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/nova_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/nova_spec.rbindex 751ccf3c833..8c25f43d9df 100644--- a/plugins/discourse-ai/spec/lib/completions/endpoints/nova_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/nova_spec.rb@@ -30,7 +30,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock dobefore { enable_current_plugin }it "should be able to make a simple request" do- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{nova_model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(nova_model)content = {"output" => {@@ -92,7 +92,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock dostub_request(:post, stream_url).to_return(status: 200, body: messages.join)- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{nova_model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(nova_model)responses = []proxy.generate("Hello!", user: user) { |partial| responses << partial }@@ -106,7 +106,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do#model.provider_params["disable_native_tools"] = true#model.save!- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{nova_model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(nova_model)prompt =DiscourseAi::Completions::Prompt.new("You are a helpful assistant.",diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_spec.rbindex 403f281bd66..3f160415f99 100644--- a/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/open_ai_spec.rb@@ -179,7 +179,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::OpenAi dodescribe "max tokens for reasoning models" doit "uses max_completion_tokens for reasoning models" domodel.update!(name: "o3-mini", max_output_tokens: 999)- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)prompt =DiscourseAi::Completions::Prompt.new("You are a bot",@@ -218,7 +218,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::OpenAi dodescribe "repeat calls" doit "can properly reset context" do- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)tools = [{@@ -299,7 +299,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::OpenAi dodescribe "max tokens remapping" doit "remaps max_tokens to max_completion_tokens for reasoning models" domodel.update!(name: "o3-mini")- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)body_parsed = nilstub_request(:post, "https://api.openai.com/v1/chat/completions").with(@@ -315,7 +315,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::OpenAi dodescribe "forced tool use" doit "can properly force tool use" do- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)tools = [{@@ -443,7 +443,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::OpenAi dodescribe "disabled tool use" doit "can properly disable tool use with :none" do- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)tools = [{@@ -534,7 +534,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::OpenAi dodescribe "image support" doit "can handle images" domodel = Fabricate(:llm_model, vision_enabled: true)- llm = DiscourseAi::Completions::Llm.proxy("custom:#{model.id}")+ llm = DiscourseAi::Completions::Llm.proxy(model)prompt =DiscourseAi::Completions::Prompt.new("You are image bot",diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/open_router_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/open_router_spec.rbindex 628c6f2781b..e9f84bb2adf 100644--- a/plugins/discourse-ai/spec/lib/completions/endpoints/open_router_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/open_router_spec.rb@@ -27,7 +27,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::OpenRouter dobody: { "choices" => [message: { role: "assistant", content: "world" }] }.to_json,)- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{open_router_model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(open_router_model)result = proxy.generate("hello", user: user)expect(result).to eq("world")@@ -64,7 +64,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::OpenRouter dobody: { "choices" => [message: { role: "assistant", content: "test response" }] }.to_json,)- proxy = DiscourseAi::Completions::Llm.proxy("custom:#{open_router_model.id}")+ proxy = DiscourseAi::Completions::Llm.proxy(open_router_model)# Request with parameters that should be ignoredproxy.generate("test", user: user, top_p: 0.9, temperature: 0.8, max_tokens: 500)diff --git a/plugins/discourse-ai/spec/lib/completions/endpoints/vllm_spec.rb b/plugins/discourse-ai/spec/lib/completions/endpoints/vllm_spec.rbindex c91ce067dc8..27bdd4feb42 100644--- a/plugins/discourse-ai/spec/lib/completions/endpoints/vllm_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/endpoints/vllm_spec.rb@@ -68,7 +68,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::Vllm dofab!(:llm_model) { Fabricate(:vllm_model) }fab!(:user)- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }let(:vllm_mock) { VllmMock.new(endpoint) }let(:compliance) dodiff --git a/plugins/discourse-ai/spec/lib/completions/llm_spec.rb b/plugins/discourse-ai/spec/lib/completions/llm_spec.rbindex ccc2c888769..3759a627972 100644--- a/plugins/discourse-ai/spec/lib/completions/llm_spec.rb+++ b/plugins/discourse-ai/spec/lib/completions/llm_spec.rb@@ -48,9 +48,7 @@ RSpec.describe DiscourseAi::Completions::Llm dobody: result,)result = +""- described_class- .proxy("custom:#{model.id}")- .generate(prompt, user: user) { |partial| result << partial }+ described_class.proxy(model).generate(prompt, user: user) { |partial| result << partial }expect(result).to eq("Hello")log = AiApiAuditLog.order("id desc").first@@ -77,7 +75,7 @@ RSpec.describe DiscourseAi::Completions::Llm do)result =- described_class.proxy("custom:#{model.id}").generate(+ described_class.proxy(model).generate("Hello",user: user,feature_name: "llm_triage",@@ -101,7 +99,7 @@ RSpec.describe DiscourseAi::Completions::Llm doDiscourseAi::Completions::Endpoints::Fake.chunk_count = 10end- let(:llm) { described_class.proxy("custom:#{fake_model.id}") }+ let(:llm) { described_class.proxy(fake_model) }let(:prompt) doDiscourseAi::Completions::Prompt.new(diff --git a/plugins/discourse-ai/spec/lib/discourse_automation/automation_spec.rb b/plugins/discourse-ai/spec/lib/discourse_automation/automation_spec.rbindex c8127d16b35..7050d6d982b 100644--- a/plugins/discourse-ai/spec/lib/discourse_automation/automation_spec.rb+++ b/plugins/discourse-ai/spec/lib/discourse_automation/automation_spec.rb@@ -19,41 +19,17 @@ RSpec.describe DiscourseAi::Automation doendend- describe "seeded models" do- let!(:llm_model) { Fabricate(:seeded_model) }- it "returns an empty list if no seeded models are allowed" do- models = DiscourseAi::Automation.available_models- expect(models).to be_empty- end-- it "returns a list of seeded models if allowed" do- SiteSetting.ai_automation_allowed_seeded_models = llm_model.id.to_s- models = DiscourseAi::Automation.available_models- expect(models.first["translated_name"]).to eq(llm_model.display_name)- end- end-describe "mixed models" dolet!(:llm_model) { Fabricate(:llm_model) }let!(:seeded_model) { Fabricate(:seeded_model) }- it "returns only the manually configured model if seeded is not allowed" do- models = DiscourseAi::Automation.available_models- expect(models.length).to eq(1)- expect(models.first["translated_name"]).to eq(llm_model.display_name)- end-- it "returns a list of seeded and custom models when seeded is allowed" do- SiteSetting.ai_automation_allowed_seeded_models = seeded_model.id.to_s+ it "returns a list of seeded and custom models" domodels = DiscourseAi::Automation.available_modelsexpect(models).to match_array([- { "translated_name" => "#{llm_model.display_name}", "id" => "custom:#{llm_model.id}" },- {- "translated_name" => "#{seeded_model.display_name}",- "id" => "custom:#{seeded_model.id}",- },+ { "translated_name" => "#{llm_model.display_name}", "id" => llm_model.id.to_s },+ { "translated_name" => "#{seeded_model.display_name}", "id" => seeded_model.id.to_s },],)enddiff --git a/plugins/discourse-ai/spec/lib/discourse_automation/llm_report_spec.rb b/plugins/discourse-ai/spec/lib/discourse_automation/llm_report_spec.rbindex f440843a57d..d6d2f467598 100644--- a/plugins/discourse-ai/spec/lib/discourse_automation/llm_report_spec.rb+++ b/plugins/discourse-ai/spec/lib/discourse_automation/llm_report_spec.rb@@ -26,12 +26,12 @@ describe DiscourseAutomation doit "can trigger via automation" doadd_automation_field("sender", user.username, type: "user")add_automation_field("receivers", [user.username], type: "email_group_user")- add_automation_field("model", "custom:#{llm_model.id}")add_automation_field("persona_id",DiscourseAi::Personas::Persona.system_personas[DiscourseAi::Personas::ReportRunner],)+ add_automation_field("model", llm_model.id)add_automation_field("title", "Weekly report")DiscourseAi::Completions::Llm.with_prepared_responses(["An Amazing Report!!!"]) do@@ -45,11 +45,11 @@ describe DiscourseAutomation doit "can target a topic" doadd_automation_field("sender", user.username, type: "user")add_automation_field("topic_id", "#{post.topic_id}")- add_automation_field("model", "custom:#{llm_model.id}")add_automation_field("persona_id",DiscourseAi::Personas::Persona.system_personas[DiscourseAi::Personas::ReportRunner],)+ add_automation_field("model", llm_model.id)DiscourseAi::Completions::Llm.with_prepared_responses(["An Amazing Report!!!"]) doautomation.trigger!diff --git a/plugins/discourse-ai/spec/lib/discourse_automation/llm_triage_spec.rb b/plugins/discourse-ai/spec/lib/discourse_automation/llm_triage_spec.rbindex 32aa822ac63..44ece3a0ef5 100644--- a/plugins/discourse-ai/spec/lib/discourse_automation/llm_triage_spec.rb+++ b/plugins/discourse-ai/spec/lib/discourse_automation/llm_triage_spec.rb@@ -29,7 +29,7 @@ describe DiscourseAi::Automation::LlmTriage doSiteSetting.tagging_enabled = trueadd_automation_field("system_prompt", "hello %%POST%%")add_automation_field("search_for_text", "bad")- add_automation_field("model", "custom:#{llm_model.id}")+ add_automation_field("model", llm_model.id)add_automation_field("category", category.id, type: "category")add_automation_field("tags", %w[aaa bbb], type: "tags")add_automation_field("hide_topic", true, type: "boolean")diff --git a/plugins/discourse-ai/spec/lib/guardian_extensions_spec.rb b/plugins/discourse-ai/spec/lib/guardian_extensions_spec.rbindex 70cd3207e57..d04445acc5d 100644--- a/plugins/discourse-ai/spec/lib/guardian_extensions_spec.rb+++ b/plugins/discourse-ai/spec/lib/guardian_extensions_spec.rb@@ -8,7 +8,7 @@ describe DiscourseAi::GuardianExtensions dobefore doenable_current_plugingroup.add(user)- assign_fake_provider_to(:ai_summarization_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_summarization_enabled = trueSiteSetting.ai_summary_gists_enabled = trueenddiff --git a/plugins/discourse-ai/spec/lib/modules/ai_helper/assistant_spec.rb b/plugins/discourse-ai/spec/lib/modules/ai_helper/assistant_spec.rbindex 0cd7b0f1e8f..c4d67fa0f23 100644--- a/plugins/discourse-ai/spec/lib/modules/ai_helper/assistant_spec.rb+++ b/plugins/discourse-ai/spec/lib/modules/ai_helper/assistant_spec.rb@@ -8,7 +8,7 @@ RSpec.describe DiscourseAi::AiHelper::Assistant dobefore doenable_current_plugin- assign_fake_provider_to(:ai_helper_model)+ assign_fake_provider_to(:ai_default_llm_model)Group.refresh_automatic_groups!enddiff --git a/plugins/discourse-ai/spec/lib/modules/ai_helper/chat_thread_titler_spec.rb b/plugins/discourse-ai/spec/lib/modules/ai_helper/chat_thread_titler_spec.rbindex b3ae54b0acd..2b68497b0ae 100644--- a/plugins/discourse-ai/spec/lib/modules/ai_helper/chat_thread_titler_spec.rb+++ b/plugins/discourse-ai/spec/lib/modules/ai_helper/chat_thread_titler_spec.rb@@ -9,7 +9,7 @@ RSpec.describe DiscourseAi::AiHelper::ChatThreadTitler dobefore doenable_current_plugin- assign_fake_provider_to(:ai_helper_model)+ assign_fake_provider_to(:ai_default_llm_model)enddescribe "#suggested_title" dodiff --git a/plugins/discourse-ai/spec/lib/modules/ai_helper/entry_point_spec.rb b/plugins/discourse-ai/spec/lib/modules/ai_helper/entry_point_spec.rbindex 5c525b2a27e..9f14ca98c0e 100644--- a/plugins/discourse-ai/spec/lib/modules/ai_helper/entry_point_spec.rb+++ b/plugins/discourse-ai/spec/lib/modules/ai_helper/entry_point_spec.rb@@ -7,7 +7,7 @@ describe DiscourseAi::AiHelper::EntryPoint dobefore { enable_current_plugin }it "will correctly localize available prompts" do- assign_fake_provider_to(:ai_helper_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.default_locale = "en"SiteSetting.allow_user_locale = trueSiteSetting.ai_helper_enabled = truediff --git a/plugins/discourse-ai/spec/lib/modules/ai_helper/painter_spec.rb b/plugins/discourse-ai/spec/lib/modules/ai_helper/painter_spec.rbindex 1a40e6f3f44..882835d2a0d 100644--- a/plugins/discourse-ai/spec/lib/modules/ai_helper/painter_spec.rb+++ b/plugins/discourse-ai/spec/lib/modules/ai_helper/painter_spec.rb@@ -7,7 +7,7 @@ RSpec.describe DiscourseAi::AiHelper::Painter dobefore doenable_current_plugin- assign_fake_provider_to(:ai_helper_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_stability_api_url = "https://api.stability.dev"SiteSetting.ai_stability_api_key = "abc"SiteSetting.ai_openai_api_key = "abc"diff --git a/plugins/discourse-ai/spec/lib/modules/automation/llm_triage_spec.rb b/plugins/discourse-ai/spec/lib/modules/automation/llm_triage_spec.rbindex 71d85ada4f7..bb8073a3ab8 100644--- a/plugins/discourse-ai/spec/lib/modules/automation/llm_triage_spec.rb+++ b/plugins/discourse-ai/spec/lib/modules/automation/llm_triage_spec.rb@@ -14,7 +14,7 @@ describe DiscourseAi::Automation::LlmTriage doDiscourseAi::Completions::Llm.with_prepared_responses(["good"]) dotriage(post: post,- model: "custom:#{llm_model.id}",+ model: llm_model.id.to_s,hide_topic: true,system_prompt: "test %%POST%%",search_for_text: "bad",@@ -29,7 +29,7 @@ describe DiscourseAi::Automation::LlmTriage doDiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) dotriage(post: post,- model: "custom:#{llm_model.id}",+ model: llm_model.id.to_s,hide_topic: true,system_prompt: "test %%POST%%",search_for_text: "bad",@@ -46,7 +46,7 @@ describe DiscourseAi::Automation::LlmTriage doDiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) dotriage(post: post,- model: "custom:#{llm_model.id}",+ model: llm_model.id.to_s,category_id: category.id,system_prompt: "test %%POST%%",search_for_text: "bad",@@ -62,7 +62,7 @@ describe DiscourseAi::Automation::LlmTriage doDiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) dotriage(post: post,- model: "custom:#{llm_model.id}",+ model: llm_model.id.to_s,system_prompt: "test %%POST%%",search_for_text: "bad",canned_reply: "test canned reply 123",@@ -81,7 +81,7 @@ describe DiscourseAi::Automation::LlmTriage doDiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) dotriage(post: post,- model: "custom:#{llm_model.id}",+ model: llm_model.id.to_s,system_prompt: "test %%POST%%",search_for_text: "bad",flag_post: true,@@ -99,7 +99,7 @@ describe DiscourseAi::Automation::LlmTriage doDiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) dotriage(post: post,- model: "custom:#{llm_model.id}",+ model: llm_model.id.to_s,system_prompt: "test %%POST%%",search_for_text: "bad",flag_post: true,@@ -116,7 +116,7 @@ describe DiscourseAi::Automation::LlmTriage doDiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) dotriage(post: post,- model: "custom:#{llm_model.id}",+ model: llm_model.id.to_s,system_prompt: "test %%POST%%",search_for_text: "bad",flag_post: true,@@ -134,7 +134,7 @@ describe DiscourseAi::Automation::LlmTriage doDiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) dotriage(post: post,- model: "custom:#{llm_model.id}",+ model: llm_model.id.to_s,system_prompt: "test %%POST%%",search_for_text: "bad",flag_post: true,@@ -160,7 +160,7 @@ describe DiscourseAi::Automation::LlmTriage doDiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) dotriage(post: post,- model: "custom:#{llm_model.id}",+ model: llm_model.id.to_s,system_prompt: "test %%POST%%",search_for_text: "bad",flag_post: true,@@ -176,7 +176,7 @@ describe DiscourseAi::Automation::LlmTriage doDiscourseAi::Completions::Llm.with_prepared_responses(["Bad.\n\nYo"]) dotriage(post: post,- model: "custom:#{llm_model.id}",+ model: llm_model.id.to_s,system_prompt: "test %%POST%%",search_for_text: "bad",flag_post: true,@@ -193,7 +193,7 @@ describe DiscourseAi::Automation::LlmTriage doDiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) dotriage(post: post,- model: "custom:#{llm_model.id}",+ model: llm_model.id.to_s,system_prompt: "test %%POST%%",search_for_text: "BAD",flag_post: true,@@ -212,7 +212,7 @@ describe DiscourseAi::Automation::LlmTriage doDiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) dotriage(post: post,- model: "custom:#{llm_model.id}",+ model: llm_model.id.to_s,system_prompt: "test %%POST%%",search_for_text: "bad",flag_post: true,@@ -231,7 +231,7 @@ describe DiscourseAi::Automation::LlmTriage doDiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do |spy|triage(post: post,- model: "custom:#{llm_model.id}",+ model: llm_model.id.to_s,system_prompt: "test %%POST%%",search_for_text: "bad",flag_post: true,@@ -251,7 +251,7 @@ describe DiscourseAi::Automation::LlmTriage doDiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) dotriage(post: post,- model: "custom:#{llm_model.id}",+ model: llm_model.id.to_s,system_prompt: "test %%POST%%",search_for_text: "bad",flag_post: true,diff --git a/plugins/discourse-ai/spec/lib/modules/automation/report_runner_spec.rb b/plugins/discourse-ai/spec/lib/modules/automation/report_runner_spec.rbindex 426df400d9c..d1b1b50221a 100644--- a/plugins/discourse-ai/spec/lib/modules/automation/report_runner_spec.rb+++ b/plugins/discourse-ai/spec/lib/modules/automation/report_runner_spec.rb@@ -43,9 +43,9 @@ module DiscourseAisender_username: user.username,receivers: ["[email protected]"],title: "test report %DATE%",- model: "custom:#{llm_model.id}",persona_id:DiscourseAi::Personas::Persona.system_personas[DiscourseAi::Personas::ReportRunner],+ model: llm_model.id,category_ids: nil,tags: nil,allow_secure_categories: false,@@ -82,9 +82,9 @@ module DiscourseAisender_username: user.username,receivers: [receiver.username],title: "test report",- model: "custom:#{llm_model.id}",persona_id:DiscourseAi::Personas::Persona.system_personas[DiscourseAi::Personas::ReportRunner],+ model: llm_model.id,category_ids: nil,tags: nil,allow_secure_categories: false,@@ -129,9 +129,9 @@ module DiscourseAisender_username: user.username,receivers: [receiver.username],title: "test report",- model: "custom:#{llm_model.id}",persona_id:DiscourseAi::Personas::Persona.system_personas[DiscourseAi::Personas::ReportRunner],+ model: llm_model.id,category_ids: nil,tags: nil,allow_secure_categories: false,@@ -174,9 +174,9 @@ module DiscourseAisender_username: user.username,receivers: [receiver.username],title: "test report",- model: "custom:#{llm_model.id}",persona_id:DiscourseAi::Personas::Persona.system_personas[DiscourseAi::Personas::ReportRunner],+ model: llm_model.id,category_ids: nil,tags: nil,allow_secure_categories: false,@@ -208,9 +208,9 @@ module DiscourseAisender_username: user.username,receivers: [group_for_reports.name],title: "group report",- model: "custom:#{llm_model.id}",persona_id:DiscourseAi::Personas::Persona.system_personas[DiscourseAi::Personas::ReportRunner],+ model: llm_model.id,category_ids: nil,tags: nil,allow_secure_categories: false,@@ -238,9 +238,9 @@ module DiscourseAisender_username: user.username,receivers: [receiver.username],title: "test report",- model: "custom:#{llm_model.id}",persona_id:DiscourseAi::Personas::Persona.system_personas[DiscourseAi::Personas::ReportRunner],+ model: llm_model.id,category_ids: nil,tags: nil,allow_secure_categories: false,diff --git a/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_search_spec.rb b/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_search_spec.rbindex 955a929b2e8..6b3a36a7b2e 100644--- a/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_search_spec.rb+++ b/plugins/discourse-ai/spec/lib/modules/embeddings/semantic_search_spec.rb@@ -12,7 +12,7 @@ RSpec.describe DiscourseAi::Embeddings::SemanticSearch dobefore doenable_current_pluginSiteSetting.ai_embeddings_selected_model = vector_def.id- assign_fake_provider_to(:ai_embeddings_semantic_search_hyde_model)+ assign_fake_provider_to(:ai_default_llm_model)enddescribe "#search_for_topics" dodiff --git a/plugins/discourse-ai/spec/lib/modules/summarization/entry_point_spec.rb b/plugins/discourse-ai/spec/lib/modules/summarization/entry_point_spec.rbindex 10f5b2732fb..1f004d20bde 100644--- a/plugins/discourse-ai/spec/lib/modules/summarization/entry_point_spec.rb+++ b/plugins/discourse-ai/spec/lib/modules/summarization/entry_point_spec.rb@@ -3,7 +3,7 @@RSpec.describe DiscourseAi::Summarization::EntryPoint dobefore doenable_current_plugin- assign_fake_provider_to(:ai_summarization_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_summarization_enabled = trueSiteSetting.ai_summary_gists_enabled = trueenddiff --git a/plugins/discourse-ai/spec/lib/modules/summarization/fold_content_spec.rb b/plugins/discourse-ai/spec/lib/modules/summarization/fold_content_spec.rbindex 5c19077f30c..f00a3cf3e57 100644--- a/plugins/discourse-ai/spec/lib/modules/summarization/fold_content_spec.rb+++ b/plugins/discourse-ai/spec/lib/modules/summarization/fold_content_spec.rb@@ -3,7 +3,7 @@RSpec.describe DiscourseAi::Summarization::FoldContent dosubject(:summarizer) { DiscourseAi::Summarization.topic_summary(topic) }- let!(:llm_model) { assign_fake_provider_to(:ai_summarization_model) }+ let!(:llm_model) { assign_fake_provider_to(:ai_default_llm_model) }fab!(:topic) { Fabricate(:topic, highest_post_number: 2) }fab!(:post_1) { Fabricate(:post, topic: topic, post_number: 1, raw: "This is a text") }diff --git a/plugins/discourse-ai/spec/lib/personas/question_consolidator_spec.rb b/plugins/discourse-ai/spec/lib/personas/question_consolidator_spec.rbindex 20a7b5733d1..2c3c2da6950 100644--- a/plugins/discourse-ai/spec/lib/personas/question_consolidator_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/question_consolidator_spec.rb@@ -1,7 +1,7 @@# frozen_string_literal: trueRSpec.describe DiscourseAi::Personas::QuestionConsolidator do- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{Fabricate(:fake_model).id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(Fabricate(:fake_model)) }let(:fake_endpoint) { DiscourseAi::Completions::Endpoints::Fake }fab!(:user)diff --git a/plugins/discourse-ai/spec/lib/personas/tools/create_artifact_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/create_artifact_spec.rbindex 1ca40156520..8205550a827 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/create_artifact_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/create_artifact_spec.rb@@ -2,7 +2,7 @@RSpec.describe DiscourseAi::Personas::Tools::CreateArtifact dofab!(:llm_model)- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }fab!(:post)before dodiff --git a/plugins/discourse-ai/spec/lib/personas/tools/create_image_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/create_image_spec.rbindex 9ce051eb9b7..f8913dfe299 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/create_image_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/create_image_spec.rb@@ -13,7 +13,7 @@ RSpec.describe DiscourseAi::Personas::Tools::CreateImage doendlet(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(gpt_35_turbo.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{gpt_35_turbo.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(gpt_35_turbo) }let(:progress_blk) { Proc.new {} }let(:create_image) { described_class.new({ prompts: prompts }, llm: llm, bot_user: bot_user) }diff --git a/plugins/discourse-ai/spec/lib/personas/tools/dall_e_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/dall_e_spec.rbindex 303c05d1ab4..afdf34d2b6b 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/dall_e_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/dall_e_spec.rb@@ -13,7 +13,7 @@ RSpec.describe DiscourseAi::Personas::Tools::DallE doendlet(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(gpt_35_turbo.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{gpt_35_turbo.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(gpt_35_turbo) }let(:progress_blk) { Proc.new {} }let(:dall_e) { described_class.new({ prompts: prompts }, llm: llm, bot_user: bot_user) }diff --git a/plugins/discourse-ai/spec/lib/personas/tools/db_schema_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/db_schema_spec.rbindex af7f12efc34..d06d38a569b 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/db_schema_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/db_schema_spec.rb@@ -3,7 +3,7 @@RSpec.describe DiscourseAi::Personas::Tools::DbSchema dofab!(:llm_model)let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }before doenable_current_plugindiff --git a/plugins/discourse-ai/spec/lib/personas/tools/discourse_meta_search_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/discourse_meta_search_spec.rbindex e343aa1ca5f..b0b9813fa70 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/discourse_meta_search_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/discourse_meta_search_spec.rb@@ -7,7 +7,7 @@ RSpec.describe DiscourseAi::Personas::Tools::DiscourseMetaSearch dofab!(:llm_model) { Fabricate(:llm_model, max_prompt_tokens: 8192) }let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }let(:progress_blk) { Proc.new {} }let(:mock_search_json) { plugin_file_from_fixtures("search.json", "search_meta").read }diff --git a/plugins/discourse-ai/spec/lib/personas/tools/edit_image_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/edit_image_spec.rbindex 2404a81ce1e..930000e19ba 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/edit_image_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/edit_image_spec.rb@@ -18,7 +18,7 @@ RSpec.describe DiscourseAi::Personas::Tools::EditImage doendlet(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(gpt_35_turbo.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{gpt_35_turbo.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(gpt_35_turbo) }let(:progress_blk) { Proc.new {} }let(:prompt) { "add a rainbow in the background" }diff --git a/plugins/discourse-ai/spec/lib/personas/tools/github_file_content_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/github_file_content_spec.rbindex 90fbd072394..ca46fbe2d6f 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/github_file_content_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/github_file_content_spec.rb@@ -2,7 +2,7 @@RSpec.describe DiscourseAi::Personas::Tools::GithubFileContent dofab!(:llm_model)- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }let(:tool) dodescribed_class.new(diff --git a/plugins/discourse-ai/spec/lib/personas/tools/github_pull_request_diff_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/github_pull_request_diff_spec.rbindex 3e8584a533f..253f59114e1 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/github_pull_request_diff_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/github_pull_request_diff_spec.rb@@ -3,7 +3,7 @@RSpec.describe DiscourseAi::Personas::Tools::GithubPullRequestDiff dolet(:bot_user) { Fabricate(:user) }fab!(:llm_model)- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }let(:tool) { described_class.new({ repo: repo, pull_id: pull_id }, bot_user: bot_user, llm: llm) }before { enable_current_plugin }diff --git a/plugins/discourse-ai/spec/lib/personas/tools/github_search_code_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/github_search_code_spec.rbindex c58ea19476e..6dacc7bd134 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/github_search_code_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/github_search_code_spec.rb@@ -3,7 +3,7 @@RSpec.describe DiscourseAi::Personas::Tools::GithubSearchCode dolet(:bot_user) { Fabricate(:user) }fab!(:llm_model)- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }let(:tool) { described_class.new({ repo: repo, query: query }, bot_user: bot_user, llm: llm) }before { enable_current_plugin }diff --git a/plugins/discourse-ai/spec/lib/personas/tools/github_search_files_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/github_search_files_spec.rbindex abfd27e8ddf..3ad6f01ac27 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/github_search_files_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/github_search_files_spec.rb@@ -2,7 +2,7 @@RSpec.describe DiscourseAi::Personas::Tools::GithubSearchFiles dofab!(:llm_model)- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model.id) }let(:tool) dodescribed_class.new(diff --git a/plugins/discourse-ai/spec/lib/personas/tools/google_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/google_spec.rbindex 512c8842bb1..7d419af12f4 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/google_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/google_spec.rb@@ -3,7 +3,7 @@RSpec.describe DiscourseAi::Personas::Tools::Google dofab!(:llm_model)let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }let(:progress_blk) { Proc.new {} }let(:search) { described_class.new({ query: "some search term" }, bot_user: bot_user, llm: llm) }diff --git a/plugins/discourse-ai/spec/lib/personas/tools/image_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/image_spec.rbindex 0e588a8cd97..461b324840a 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/image_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/image_spec.rb@@ -21,7 +21,7 @@ RSpec.describe DiscourseAi::Personas::Tools::Image dotoggle_enabled_bots(bots: [gpt_35_turbo])end- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{gpt_35_turbo.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(gpt_35_turbo) }let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(gpt_35_turbo.name) }diff --git a/plugins/discourse-ai/spec/lib/personas/tools/javascript_evaluator_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/javascript_evaluator_spec.rbindex caff3b271c3..d356370eef8 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/javascript_evaluator_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/javascript_evaluator_spec.rb@@ -3,7 +3,7 @@RSpec.describe DiscourseAi::Personas::Tools::JavascriptEvaluator dofab!(:llm_model)let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }let(:progress_blk) { Proc.new {} }before dodiff --git a/plugins/discourse-ai/spec/lib/personas/tools/list_categories_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/list_categories_spec.rbindex bc1cac3c737..64ba14723ee 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/list_categories_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/list_categories_spec.rb@@ -3,7 +3,7 @@RSpec.describe DiscourseAi::Personas::Tools::ListCategories dofab!(:llm_model)let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }before doenable_current_plugindiff --git a/plugins/discourse-ai/spec/lib/personas/tools/list_tags_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/list_tags_spec.rbindex 541bd936222..a4e604cecc0 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/list_tags_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/list_tags_spec.rb@@ -3,7 +3,7 @@RSpec.describe DiscourseAi::Personas::Tools::ListTags dofab!(:llm_model)let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }before doenable_current_plugindiff --git a/plugins/discourse-ai/spec/lib/personas/tools/read_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/read_spec.rbindex d756bee67c9..6f347661b34 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/read_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/read_spec.rb@@ -3,7 +3,7 @@RSpec.describe DiscourseAi::Personas::Tools::Read dofab!(:llm_model)let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }let(:tool) { described_class.new({ topic_id: topic_with_tags.id }, bot_user: bot_user, llm: llm) }fab!(:parent_category) { Fabricate(:category, name: "animals") }diff --git a/plugins/discourse-ai/spec/lib/personas/tools/researcher_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/researcher_spec.rbindex d5ea34c60c0..7591eaa0c50 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/researcher_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/researcher_spec.rb@@ -6,7 +6,7 @@ RSpec.describe DiscourseAi::Personas::Tools::Researcher dofab!(:llm_model)let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }let(:progress_blk) { Proc.new {} }fab!(:admin)diff --git a/plugins/discourse-ai/spec/lib/personas/tools/search_settings_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/search_settings_spec.rbindex f43db552496..c89399ad63c 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/search_settings_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/search_settings_spec.rb@@ -3,7 +3,7 @@RSpec.describe DiscourseAi::Personas::Tools::SearchSettings dofab!(:llm_model)let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }let(:fake_settings) do[diff --git a/plugins/discourse-ai/spec/lib/personas/tools/search_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/search_spec.rbindex d9ddee462b6..0994b381ae4 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/search_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/search_spec.rb@@ -6,7 +6,7 @@ RSpec.describe DiscourseAi::Personas::Tools::Search dofab!(:llm_model)let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }let(:progress_blk) { Proc.new {} }fab!(:admin)@@ -108,7 +108,8 @@ RSpec.describe DiscourseAi::Personas::Tools::Search doafter { DiscourseAi::Embeddings::SemanticSearch.clear_cache_for(query) }it "supports semantic search when enabled" do- assign_fake_provider_to(:ai_embeddings_semantic_search_hyde_model)+ assign_fake_provider_to(:ai_default_llm_model)+vector_def = Fabricate(:embedding_definition)SiteSetting.ai_embeddings_selected_model = vector_def.idSiteSetting.ai_embeddings_semantic_search_enabled = truediff --git a/plugins/discourse-ai/spec/lib/personas/tools/setting_context_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/setting_context_spec.rbindex c5e87513eb3..0db9e63487e 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/setting_context_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/setting_context_spec.rb@@ -12,7 +12,7 @@ RSpec.describe DiscourseAi::Personas::Tools::SettingContext, if: has_rg? dofab!(:llm_model)let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }before doenable_current_plugindiff --git a/plugins/discourse-ai/spec/lib/personas/tools/summarize_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/summarize_spec.rbindex de5ce194394..139c13d787a 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/summarize_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/summarize_spec.rb@@ -3,7 +3,7 @@RSpec.describe DiscourseAi::Personas::Tools::Summarize dofab!(:llm_model)let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }let(:progress_blk) { Proc.new {} }before dodiff --git a/plugins/discourse-ai/spec/lib/personas/tools/time_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/time_spec.rbindex 3ddd126d2d8..8a9b707d6d9 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/time_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/time_spec.rb@@ -3,7 +3,7 @@RSpec.describe DiscourseAi::Personas::Tools::Time dofab!(:llm_model)let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }before doenable_current_plugindiff --git a/plugins/discourse-ai/spec/lib/personas/tools/web_browser_spec.rb b/plugins/discourse-ai/spec/lib/personas/tools/web_browser_spec.rbindex 2cf9922544c..cccd883338b 100644--- a/plugins/discourse-ai/spec/lib/personas/tools/web_browser_spec.rb+++ b/plugins/discourse-ai/spec/lib/personas/tools/web_browser_spec.rb@@ -3,7 +3,7 @@RSpec.describe DiscourseAi::Personas::Tools::WebBrowser dofab!(:llm_model)let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }before doenable_current_plugindiff --git a/plugins/discourse-ai/spec/lib/translation/base_translator_spec.rb b/plugins/discourse-ai/spec/lib/translation/base_translator_spec.rbindex a9b0541b490..56dada511f1 100644--- a/plugins/discourse-ai/spec/lib/translation/base_translator_spec.rb+++ b/plugins/discourse-ai/spec/lib/translation/base_translator_spec.rb@@ -9,11 +9,7 @@ describe DiscourseAi::Translation::BaseTranslator dobefore doenable_current_plugin-- Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")- end-+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_translation_enabled = trueenddiff --git a/plugins/discourse-ai/spec/lib/translation/category_localizer_spec.rb b/plugins/discourse-ai/spec/lib/translation/category_localizer_spec.rbindex 05289680017..2762c3772ef 100644--- a/plugins/discourse-ai/spec/lib/translation/category_localizer_spec.rb+++ b/plugins/discourse-ai/spec/lib/translation/category_localizer_spec.rb@@ -5,10 +5,7 @@ describe DiscourseAi::Translation::CategoryLocalizer dobefore doenable_current_plugin-- Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")- end+ assign_fake_provider_to(:ai_default_llm_model)enddef post_raw_translator_stub(opts)diff --git a/plugins/discourse-ai/spec/lib/translation/entry_point_spec.rb b/plugins/discourse-ai/spec/lib/translation/entry_point_spec.rbindex 9459c400cae..e826b87e667 100644--- a/plugins/discourse-ai/spec/lib/translation/entry_point_spec.rb+++ b/plugins/discourse-ai/spec/lib/translation/entry_point_spec.rb@@ -2,10 +2,8 @@describe DiscourseAi::Translation::EntryPoint dobefore do+ assign_fake_provider_to(:ai_default_llm_model)enable_current_plugin- Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")- endSiteSetting.ai_translation_enabled = trueSiteSetting.content_localization_supported_locales = "en"end@@ -58,9 +56,8 @@ describe DiscourseAi::Translation::EntryPoint dofab!(:non_first_post) { Fabricate(:post, post_number: 2) }before do- Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")- end+ enable_current_plugin+ assign_fake_provider_to(:ai_default_llm_model)endit "enqueues detect topic locale and translate topic job" dodiff --git a/plugins/discourse-ai/spec/lib/translation/language_detector_spec.rb b/plugins/discourse-ai/spec/lib/translation/language_detector_spec.rbindex d52f12f3749..885e4b82fc3 100644--- a/plugins/discourse-ai/spec/lib/translation/language_detector_spec.rb+++ b/plugins/discourse-ai/spec/lib/translation/language_detector_spec.rb@@ -9,10 +9,7 @@ describe DiscourseAi::Translation::LanguageDetector dobefore doenable_current_plugin-- Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("ai_translation_model=", "custom:#{fake_llm.id}")- end+ assign_fake_provider_to(:ai_default_llm_model)enddescribe ".detect" do@@ -40,7 +37,7 @@ describe DiscourseAi::Translation::LanguageDetector doallow(DiscourseAi::Completions::Prompt).to receive(:new).and_return(mock_prompt)allow(DiscourseAi::Completions::Llm).to receive(:proxy).with(- SiteSetting.ai_translation_model,+ SiteSetting.ai_default_llm_model,).and_return(mock_llm)allow(mock_llm).to receive(:generate).with(mock_prompt,diff --git a/plugins/discourse-ai/spec/lib/utils/search_spec.rb b/plugins/discourse-ai/spec/lib/utils/search_spec.rbindex a61449b0f36..0c45b145bce 100644--- a/plugins/discourse-ai/spec/lib/utils/search_spec.rb+++ b/plugins/discourse-ai/spec/lib/utils/search_spec.rb@@ -145,7 +145,8 @@ RSpec.describe DiscourseAi::Utils::Search doendit "includes semantic search results when enabled" do- assign_fake_provider_to(:ai_embeddings_semantic_search_hyde_model)+ assign_fake_provider_to(:ai_default_llm_model)+vector_def = Fabricate(:embedding_definition)SiteSetting.ai_embeddings_selected_model = vector_def.idSiteSetting.ai_embeddings_semantic_search_enabled = true@@ -169,7 +170,8 @@ RSpec.describe DiscourseAi::Utils::Search doendit "can disable semantic search with hyde parameter" do- assign_fake_provider_to(:ai_embeddings_semantic_search_hyde_model)+ assign_fake_provider_to(:ai_default_llm_model)+vector_def = Fabricate(:embedding_definition)SiteSetting.ai_embeddings_selected_model = vector_def.idSiteSetting.ai_embeddings_semantic_search_enabled = truediff --git a/plugins/discourse-ai/spec/models/ai_persona_spec.rb b/plugins/discourse-ai/spec/models/ai_persona_spec.rbindex d93dbf34acc..347e238ead3 100644--- a/plugins/discourse-ai/spec/models/ai_persona_spec.rb+++ b/plugins/discourse-ai/spec/models/ai_persona_spec.rb@@ -213,20 +213,6 @@ RSpec.describe AiPersona do)end- it "validates allowed seeded model" do- basic_persona.default_llm_id = seeded_llm_model.id-- SiteSetting.ai_bot_allowed_seeded_models = ""-- expect(basic_persona.valid?).to eq(false)- expect(basic_persona.errors[:default_llm]).to include(- I18n.t("discourse_ai.llm.configuration.invalid_seeded_model"),- )-- SiteSetting.ai_bot_allowed_seeded_models = "-1"- expect(basic_persona.valid?).to eq(true)- end-it "does not leak caches between sites" doAiPersona.create!(name: "pun_bot",diff --git a/plugins/discourse-ai/spec/models/ai_tool_spec.rb b/plugins/discourse-ai/spec/models/ai_tool_spec.rbindex 9417f241e3c..9c970970ef3 100644--- a/plugins/discourse-ai/spec/models/ai_tool_spec.rb+++ b/plugins/discourse-ai/spec/models/ai_tool_spec.rb@@ -2,7 +2,7 @@RSpec.describe AiTool dofab!(:llm_model) { Fabricate(:llm_model, name: "claude-2") }- let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }+ let(:llm) { DiscourseAi::Completions::Llm.proxy(llm_model) }fab!(:topic)fab!(:post) { Fabricate(:post, topic: topic, raw: "bananas are a tasty fruit") }fab!(:bot_user) { Discourse.system_user }diff --git a/plugins/discourse-ai/spec/models/user_option_spec.rb b/plugins/discourse-ai/spec/models/user_option_spec.rbindex 943124bf163..2f7678547fe 100644--- a/plugins/discourse-ai/spec/models/user_option_spec.rb+++ b/plugins/discourse-ai/spec/models/user_option_spec.rb@@ -10,6 +10,7 @@ RSpec.describe UserOption dobefore doenable_current_plugin+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_bot_enabled = trueenddiff --git a/plugins/discourse-ai/spec/plugin_helper.rb b/plugins/discourse-ai/spec/plugin_helper.rbindex 0346df7cac9..4e2a58a7fd2 100644--- a/plugins/discourse-ai/spec/plugin_helper.rb+++ b/plugins/discourse-ai/spec/plugin_helper.rb@@ -12,7 +12,7 @@ module DiscourseAi::ChatBotHelperdef assign_fake_provider_to(setting_name)Fabricate(:fake_model).tap do |fake_llm|- SiteSetting.public_send("#{setting_name}=", "custom:#{fake_llm.id}")+ SiteSetting.public_send("#{setting_name}=", "#{fake_llm.id}")endenddiff --git a/plugins/discourse-ai/spec/plugin_spec.rb b/plugins/discourse-ai/spec/plugin_spec.rbindex 85052c5256c..1c9da2a76f1 100644--- a/plugins/discourse-ai/spec/plugin_spec.rb+++ b/plugins/discourse-ai/spec/plugin_spec.rb@@ -7,7 +7,7 @@ describe Plugin::Instance dofab!(:user)before do- assign_fake_provider_to(:ai_helper_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_helper_enabled = trueSiteSetting.ai_helper_illustrate_post_model = "disabled"Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)diff --git a/plugins/discourse-ai/spec/requests/admin/ai_features_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/ai_features_controller_spec.rbindex f2e96a38795..d77c30d72af 100644--- a/plugins/discourse-ai/spec/requests/admin/ai_features_controller_spec.rb+++ b/plugins/discourse-ai/spec/requests/admin/ai_features_controller_spec.rb@@ -11,6 +11,7 @@ RSpec.describe DiscourseAi::Admin::AiFeaturesController dobefore doenable_current_pluginsign_in(admin)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_bot_enabled = trueenddiff --git a/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rbindex f62abdec60a..b94c381ffc9 100644--- a/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb+++ b/plugins/discourse-ai/spec/requests/admin/ai_llms_controller_spec.rb@@ -50,20 +50,19 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController doit "lists enabled features on appropriate LLMs" doSiteSetting.ai_bot_enabled = true+ fake_model = assign_fake_provider_to(:ai_default_llm_model)# setting the setting calls the modelDiscourseAi::Completions::Llm.with_prepared_responses(["OK"]) do- SiteSetting.ai_helper_model = "custom:#{llm_model.id}"+ SiteSetting.ai_helper_proofreader_persona = ai_persona.idSiteSetting.ai_helper_enabled = trueendDiscourseAi::Completions::Llm.with_prepared_responses(["OK"]) do- SiteSetting.ai_summarization_model = "custom:#{llm_model2.id}"SiteSetting.ai_summarization_enabled = trueendDiscourseAi::Completions::Llm.with_prepared_responses(["OK"]) do- SiteSetting.ai_embeddings_semantic_search_hyde_model = "custom:#{llm_model2.id}"SiteSetting.ai_embeddings_semantic_search_enabled = trueend@@ -72,15 +71,18 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController dollms = response.parsed_body["ai_llms"]model_json = llms.find { |m| m["id"] == llm_model.id }- expect(model_json["used_by"]).to contain_exactly(- { "type" => "ai_bot" },- { "type" => "ai_helper" },- )+ expect(model_json["used_by"]).to contain_exactly({ "type" => "ai_bot" })model2_json = llms.find { |m| m["id"] == llm_model2.id }expect(model2_json["used_by"]).to contain_exactly({ "type" => "ai_persona", "name" => "Cool persona", "id" => ai_persona.id },+ { "type" => "ai_helper", "name" => "Proofread text" },+ )++ model3_json = llms.find { |m| m["id"] == fake_model.id }++ expect(model3_json["used_by"]).to contain_exactly({ "type" => "ai_summarization" },{ "type" => "ai_embeddings_semantic_search" },)@@ -472,16 +474,16 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController doerror_type: "validation",}- WebMock.stub_request(:post, test_attrs[:url]).to_return(- status: 422,- body: error_message.to_json,- )+ error =+ DiscourseAi::Completions::Endpoints::Base::CompletionFailed.new(error_message.to_json)- get "/admin/plugins/discourse-ai/ai-llms/test.json", params: { ai_llm: test_attrs }+ DiscourseAi::Completions::Llm.with_prepared_responses([error]) do+ get "/admin/plugins/discourse-ai/ai-llms/test.json", params: { ai_llm: test_attrs }- expect(response).to be_successful- expect(response.parsed_body["success"]).to eq(false)- expect(response.parsed_body["error"]).to eq(error_message.to_json)+ expect(response).to be_successful+ expect(response.parsed_body["success"]).to eq(false)+ expect(response.parsed_body["error"]).to eq(error_message.to_json)+ endendendend@@ -499,7 +501,6 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController doit "logs staff action when deleting an LLM model" do# Capture the model details before deletion for comparison- model_id = llm_model.idmodel_display_name = llm_model.display_name# Delete the model@@ -516,13 +517,15 @@ RSpec.describe DiscourseAi::Admin::AiLlmsController doexpect(history.subject).to eq(model_display_name) # Verify subject is set to display_nameend- it "validates the model is not in use" do- fake_llm = assign_fake_provider_to(:ai_helper_model)-- delete "/admin/plugins/discourse-ai/ai-llms/#{fake_llm.id}.json"+ context "with llms configured" do+ fab!(:ai_persona) { Fabricate(:ai_persona, default_llm_id: llm_model.id) }- expect(response.status).to eq(409)- expect(fake_llm.reload).to eq(fake_llm)+ before { assign_fake_provider_to(:ai_helper_model) }+ it "validates the model is not in use" do+ delete "/admin/plugins/discourse-ai/ai-llms/#{llm_model.id}.json"+ expect(response.status).to eq(409)+ expect(llm_model.reload).to eq(llm_model)+ endendit "cleans up companion users before deleting the model" dodiff --git a/plugins/discourse-ai/spec/requests/admin/ai_spam_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/ai_spam_controller_spec.rbindex 8a05441c8ec..246b35f15eb 100644--- a/plugins/discourse-ai/spec/requests/admin/ai_spam_controller_spec.rb+++ b/plugins/discourse-ai/spec/requests/admin/ai_spam_controller_spec.rb@@ -30,30 +30,6 @@ RSpec.describe DiscourseAi::Admin::AiSpamController doexpect(AiModerationSetting.spam.data["custom_instructions"]).to eq("custom instructions")end- it "denies update for disallowed seeded llm" do- seeded_llm = Fabricate(:llm_model, id: -1)-- put "/admin/plugins/discourse-ai/ai-spam.json",- params: {- is_enabled: true,- llm_model_id: seeded_llm.id,- custom_instructions: "custom instructions",- }-- expect(response.status).to eq(422)-- SiteSetting.ai_spam_detection_model_allowed_seeded_models = seeded_llm.id.to_s-- put "/admin/plugins/discourse-ai/ai-spam.json",- params: {- is_enabled: true,- llm_model_id: seeded_llm.id,- custom_instructions: "custom instructions",- }-- expect(response.status).to eq(200)- end-it "validates the selected persona has a valid response format" doai_persona = Fabricate(:ai_persona, response_format: nil)@@ -81,26 +57,6 @@ RSpec.describe DiscourseAi::Admin::AiSpamController doexpect(AiModerationSetting.spam.ai_persona_id).to eq(ai_persona.id)end- it "ensures that seeded llm ID is properly passed and allowed" do- seeded_llm = Fabricate(:seeded_model)-- SiteSetting.ai_spam_detection_model_allowed_seeded_models = [- llm_model.id,- seeded_llm.id,- ].join("|")-- put "/admin/plugins/discourse-ai/ai-spam.json",- params: {- is_enabled: true,- llm_model_id: seeded_llm.id,- custom_instructions: "custom instructions",- }- expect(SiteSetting.ai_spam_detection_model_allowed_seeded_models).to eq(- "#{llm_model.id}|#{seeded_llm.id}",- )- expect(response.status).to eq(200)- end-it "can not enable spam detection without a model selected" doput "/admin/plugins/discourse-ai/ai-spam.json",params: {@@ -353,18 +309,9 @@ RSpec.describe DiscourseAi::Admin::AiSpamController doAiModerationSetting.create!(setting_type: :spam, llm_model_id: llm_model.id)end- it "correctly filters seeded llms" do+ it "lists available LLMs" doSiteSetting.ai_spam_detection_enabled = true- seeded_llm = Fabricate(:seeded_model)-- get "/admin/plugins/discourse-ai/ai-spam.json"- expect(response.status).to eq(200)- json = response.parsed_body-- # only includes fabricated model- expect(json["available_llms"].length).to eq(1)-- SiteSetting.ai_spam_detection_model_allowed_seeded_models = seeded_llm.id.to_s+ Fabricate(:seeded_model)get "/admin/plugins/discourse-ai/ai-spam.json"expect(response.status).to eq(200)diff --git a/plugins/discourse-ai/spec/requests/ai_helper/assistant_controller_spec.rb b/plugins/discourse-ai/spec/requests/ai_helper/assistant_controller_spec.rbindex e9a4e064fe9..1c82b422dec 100644--- a/plugins/discourse-ai/spec/requests/ai_helper/assistant_controller_spec.rb+++ b/plugins/discourse-ai/spec/requests/ai_helper/assistant_controller_spec.rb@@ -6,7 +6,8 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController dobefore doenable_current_plugin- assign_fake_provider_to(:ai_helper_model)+ assign_fake_provider_to(:ai_default_llm_model)+ SiteSetting.ai_helper_enabled = trueenddescribe "#stream_suggestion" do@@ -309,8 +310,6 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController doendlet(:bad_caption) { "A picture of a cat \nsitting on a |table|" }- before { assign_fake_provider_to(:ai_helper_image_caption_model) }-def request_caption(params, caption = "A picture of a cat sitting on a table")DiscourseAi::Completions::Llm.with_prepared_responses([caption]) dopost "/discourse-ai/ai-helper/caption_image", params: params@@ -416,7 +415,6 @@ RSpec.describe DiscourseAi::AiHelper::AssistantController doenable_current_pluginsetup_s3stub_s3_store- assign_fake_provider_to(:ai_helper_image_caption_model)SiteSetting.secure_uploads = trueSiteSetting.composer_ai_helper_allowed_groups = Group::AUTO_GROUPS[:trust_level_1]diff --git a/plugins/discourse-ai/spec/requests/embeddings/embeddings_controller_spec.rb b/plugins/discourse-ai/spec/requests/embeddings/embeddings_controller_spec.rbindex 6c3e6a18323..50615e5f4fd 100644--- a/plugins/discourse-ai/spec/requests/embeddings/embeddings_controller_spec.rb+++ b/plugins/discourse-ai/spec/requests/embeddings/embeddings_controller_spec.rb@@ -121,7 +121,7 @@ describe DiscourseAi::Embeddings::EmbeddingsController doendit "doesn't skip HyDE if the hyde param is missing" do- assign_fake_provider_to(:ai_embeddings_semantic_search_hyde_model)+ assign_fake_provider_to(:ai_default_llm_model)index(topic)index(topic_in_subcategory)diff --git a/plugins/discourse-ai/spec/requests/summarization/chat_summary_controller_spec.rb b/plugins/discourse-ai/spec/requests/summarization/chat_summary_controller_spec.rbindex 08ed32e80fa..607013f5725 100644--- a/plugins/discourse-ai/spec/requests/summarization/chat_summary_controller_spec.rb+++ b/plugins/discourse-ai/spec/requests/summarization/chat_summary_controller_spec.rb@@ -9,7 +9,7 @@ RSpec.describe DiscourseAi::Summarization::ChatSummaryController dogroup.add(current_user)- assign_fake_provider_to(:ai_summarization_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_summarization_enabled = trueSiteSetting.ai_custom_summarization_allowed_groups = group.iddiff --git a/plugins/discourse-ai/spec/requests/summarization/summary_controller_spec.rb b/plugins/discourse-ai/spec/requests/summarization/summary_controller_spec.rbindex 782c9988319..7bd3c34e031 100644--- a/plugins/discourse-ai/spec/requests/summarization/summary_controller_spec.rb+++ b/plugins/discourse-ai/spec/requests/summarization/summary_controller_spec.rb@@ -8,7 +8,7 @@ RSpec.describe DiscourseAi::Summarization::SummaryController dobefore doenable_current_plugin- assign_fake_provider_to(:ai_summarization_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_summarization_enabled = trueenddiff --git a/plugins/discourse-ai/spec/services/discourse_ai/persona_importer_spec.rb b/plugins/discourse-ai/spec/services/discourse_ai/persona_importer_spec.rbindex 4c2c0cb5bce..25b5b30b4ef 100644--- a/plugins/discourse-ai/spec/services/discourse_ai/persona_importer_spec.rb+++ b/plugins/discourse-ai/spec/services/discourse_ai/persona_importer_spec.rb@@ -68,7 +68,7 @@ RSpec.describe DiscourseAi::PersonaImporter doexpect { importer.import! }.to raise_error(DiscourseAi::PersonaImporter::ImportError,) do |error|- expect(error.conflicts).to eq(custom_tools: %w[browse_web calculator])+ expect(error.conflicts[:custom_tools]).to contain_exactly("browse_web", "calculator")endendend@@ -80,10 +80,8 @@ RSpec.describe DiscourseAi::PersonaImporter doexpect { importer.import! }.to raise_error(DiscourseAi::PersonaImporter::ImportError,) do |error|- expect(error.conflicts).to eq(- persona: "Test Persona",- custom_tools: %w[browse_web calculator],- )+ expect(error.conflicts[:persona]).to eq("Test Persona")+ expect(error.conflicts[:custom_tools]).to contain_exactly("browse_web", "calculator")endendenddiff --git a/plugins/discourse-ai/spec/services/discourse_ai/topic_summarization_spec.rb b/plugins/discourse-ai/spec/services/discourse_ai/topic_summarization_spec.rbindex b8a77bb1679..d0ee7712b77 100644--- a/plugins/discourse-ai/spec/services/discourse_ai/topic_summarization_spec.rb+++ b/plugins/discourse-ai/spec/services/discourse_ai/topic_summarization_spec.rb@@ -8,7 +8,7 @@ describe DiscourseAi::TopicSummarization dobefore doenable_current_plugin- assign_fake_provider_to(:ai_summarization_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_summarization_enabled = trueenddiff --git a/plugins/discourse-ai/spec/services/problem_check/ai_llm_status_spec.rb b/plugins/discourse-ai/spec/services/problem_check/ai_llm_status_spec.rbindex 49771c8cd15..804a7a9cd36 100644--- a/plugins/discourse-ai/spec/services/problem_check/ai_llm_status_spec.rb+++ b/plugins/discourse-ai/spec/services/problem_check/ai_llm_status_spec.rb@@ -4,6 +4,7 @@ RSpec.describe ProblemCheck::AiLlmStatus dosubject(:check) { described_class.new }fab!(:llm_model)+ fab!(:ai_persona) { Fabricate(:ai_persona, default_llm_id: llm_model.id) }let(:post_url) { "https://api.openai.com/v1/chat/completions" }let(:success_response) do@@ -24,7 +25,8 @@ RSpec.describe ProblemCheck::AiLlmStatus dobefore dostub_request(:post, post_url).to_return(status: 200, body: success_response, headers: {})- SiteSetting.ai_summarization_model = "custom:#{llm_model.id}"+ assign_fake_provider_to(:ai_default_llm_model)+ SiteSetting.ai_summarization_persona = ai_persona.idSiteSetting.ai_summarization_enabled = trueenddiff --git a/plugins/discourse-ai/spec/system/admin_ai_features_spec.rb b/plugins/discourse-ai/spec/system/admin_ai_features_spec.rbindex 6e7ea704cff..e4e5458e917 100644--- a/plugins/discourse-ai/spec/system/admin_ai_features_spec.rb+++ b/plugins/discourse-ai/spec/system/admin_ai_features_spec.rb@@ -14,7 +14,7 @@ RSpec.describe "Admin AI features configuration", type: :system doenable_current_pluginsummarization_persona.allowed_group_ids = [group_1.id, group_2.id]summarization_persona.save!- assign_fake_provider_to(:ai_summarization_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_summarization_enabled = trueSiteSetting.ai_summarization_persona = summarization_persona.idsign_in(admin)diff --git a/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb b/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rbindex 75bb2929fa0..9e92c383e3c 100644--- a/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb+++ b/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb@@ -8,7 +8,7 @@ RSpec.describe "AI Composer helper", type: :system dobefore doenable_current_pluginGroup.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)- assign_fake_provider_to(:ai_helper_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_helper_enabled = trueJobs.run_immediately!sign_in(user)diff --git a/plugins/discourse-ai/spec/system/ai_helper/ai_image_caption_spec.rb b/plugins/discourse-ai/spec/system/ai_helper/ai_image_caption_spec.rbindex 2ed0ed12e27..4d23bf65a4b 100644--- a/plugins/discourse-ai/spec/system/ai_helper/ai_image_caption_spec.rb+++ b/plugins/discourse-ai/spec/system/ai_helper/ai_image_caption_spec.rb@@ -24,8 +24,7 @@ RSpec.describe "AI image caption", type: :system dobefore doenable_current_pluginGroup.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)- assign_fake_provider_to(:ai_helper_model)- assign_fake_provider_to(:ai_helper_image_caption_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_helper_enabled = trueSiteSetting.ai_helper_enabled_features = "image_caption"sign_in(user)diff --git a/plugins/discourse-ai/spec/system/ai_helper/ai_post_helper_spec.rb b/plugins/discourse-ai/spec/system/ai_helper/ai_post_helper_spec.rbindex e69e8d6065f..1cbb930bd0c 100644--- a/plugins/discourse-ai/spec/system/ai_helper/ai_post_helper_spec.rb+++ b/plugins/discourse-ai/spec/system/ai_helper/ai_post_helper_spec.rb@@ -29,7 +29,7 @@ RSpec.describe "AI Post helper", type: :system dobefore doenable_current_pluginGroup.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)- assign_fake_provider_to(:ai_helper_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_helper_enabled = trueJobs.run_immediately!sign_in(user)diff --git a/plugins/discourse-ai/spec/system/ai_helper/ai_proofreading_spec.rb b/plugins/discourse-ai/spec/system/ai_helper/ai_proofreading_spec.rbindex 9b4e6166b14..911d2ff8a91 100644--- a/plugins/discourse-ai/spec/system/ai_helper/ai_proofreading_spec.rb+++ b/plugins/discourse-ai/spec/system/ai_helper/ai_proofreading_spec.rb@@ -7,7 +7,7 @@ RSpec.describe "AI Composer Proofreading Features", type: :system dobefore doenable_current_plugin- assign_fake_provider_to(:ai_helper_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_helper_enabled = true# This needs to be done because the streaming suggestions for composerdiff --git a/plugins/discourse-ai/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb b/plugins/discourse-ai/spec/system/ai_helper/ai_split_topic_suggestion_spec.rbindex 248ef6f1429..a993f004bb2 100644--- a/plugins/discourse-ai/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb+++ b/plugins/discourse-ai/spec/system/ai_helper/ai_split_topic_suggestion_spec.rb@@ -40,7 +40,7 @@ RSpec.describe "AI Post helper", type: :system dobefore doenable_current_pluginGroup.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)- assign_fake_provider_to(:ai_helper_model)+ assign_fake_provider_to(:ai_default_llm_model)SiteSetting.ai_helper_enabled = truesign_in(user)enddiff --git a/plugins/discourse-ai/spec/system/ai_moderation/ai_spam_spec.rb b/plugins/discourse-ai/spec/system/ai_moderation/ai_spam_spec.rbindex 926058e7f5a..4e19572f29d 100644--- a/plugins/discourse-ai/spec/system/ai_moderation/ai_spam_spec.rb+++ b/plugins/discourse-ai/spec/system/ai_moderation/ai_spam_spec.rb@@ -2,47 +2,51 @@RSpec.describe "AI Spam Configuration", type: :system dofab!(:admin)- let(:llm_model) { Fabricate(:llm_model) }before doenable_current_pluginsign_in(admin)end- it "can properly configure spam settings" do- visit "/admin/plugins/discourse-ai/ai-spam"+ context "when no LLMs are configured" do+ it "shows the placeholder when no LLM is configured" do+ visit "/admin/plugins/discourse-ai/ai-spam"- expect(page).to have_css(".ai-spam__llm-placeholder")+ expect(page).to have_css(".ai-spam__llm-placeholder")- toggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle")+ toggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle")- toggle.toggle- dialog = PageObjects::Components::Dialog.new- expect(dialog).to have_content(I18n.t("discourse_ai.llm.configuration.must_select_model"))- dialog.click_ok+ toggle.toggle+ dialog = PageObjects::Components::Dialog.new+ expect(dialog).to have_content(I18n.t("discourse_ai.llm.configuration.must_select_model"))+ dialog.click_ok- expect(toggle.unchecked?).to eq(true)-- llm_model- visit "/admin/plugins/discourse-ai/ai-spam"+ expect(toggle.unchecked?).to eq(true)+ end+ end+ context "when LLMs are configured" do+ fab!(:llm_model)+ it "can properly configure spam settings" do+ visit "/admin/plugins/discourse-ai/ai-spam"- toggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle")- toggle.toggle+ toggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle")+ toggle.toggle- try_until_success { expect(AiModerationSetting.spam&.llm_model_id).to eq(llm_model.id) }+ try_until_success { expect(AiModerationSetting.spam&.llm_model_id).to eq(llm_model.id) }- find(".ai-spam__instructions-input").fill_in(with: "Test spam detection instructions")- find(".ai-spam__instructions-save").click+ find(".ai-spam__instructions-input").fill_in(with: "Test spam detection instructions")+ find(".ai-spam__instructions-save").click- toasts = PageObjects::Components::Toasts.new- expect(toasts).to have_content(I18n.t("js.discourse_ai.spam.settings_saved"))+ toasts = PageObjects::Components::Toasts.new+ expect(toasts).to have_content(I18n.t("js.discourse_ai.spam.settings_saved"))- expect(AiModerationSetting.spam.custom_instructions).to eq("Test spam detection instructions")+ expect(AiModerationSetting.spam.custom_instructions).to eq("Test spam detection instructions")- visit "/admin/plugins/discourse-ai/ai-llms"+ visit "/admin/plugins/discourse-ai/ai-llms"- expect(find(".ai-llm-list-editor__usages")).to have_content(- I18n.t("js.discourse_ai.llms.usage.ai_spam"),- )+ expect(find(".ai-llm-list-editor__usages")).to have_content(+ I18n.t("js.discourse_ai.llms.usage.ai_spam"),+ )+ endendenddiff --git a/plugins/discourse-ai/spec/system/ai_user_preferences_spec.rb b/plugins/discourse-ai/spec/system/ai_user_preferences_spec.rbindex 4285a5cf49d..93d9634cb96 100644--- a/plugins/discourse-ai/spec/system/ai_user_preferences_spec.rb+++ b/plugins/discourse-ai/spec/system/ai_user_preferences_spec.rb@@ -12,8 +12,7 @@ RSpec.describe "User AI preferences", type: :system doenable_current_pluginSiteSetting.ai_bot_discover_persona = discovery_persona.idGroup.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)- assign_fake_provider_to(:ai_helper_model)- assign_fake_provider_to(:ai_helper_image_caption_model)+ assign_fake_provider_to(:ai_default_llm_model)sign_in(user)enddiff --git a/plugins/discourse-ai/spec/system/summarization/chat_summarization_spec.rb b/plugins/discourse-ai/spec/system/summarization/chat_summarization_spec.rbindex 8f9f340a47c..1d49a3667c0 100644--- a/plugins/discourse-ai/spec/system/summarization/chat_summarization_spec.rb+++ b/plugins/discourse-ai/spec/system/summarization/chat_summarization_spec.rb@@ -13,7 +13,7 @@ RSpec.describe "Summarize a channel since your last visit", type: :system dogroup.add(current_user)- assign_fake_provider_to(:ai_summarization_model)+ assign_fake_provider_to(:ai_default_llm_model)assign_persona_to(:ai_summarization_persona, [group.id])SiteSetting.ai_summarization_enabled = truediff --git a/plugins/discourse-ai/spec/system/summarization/topic_summarization_spec.rb b/plugins/discourse-ai/spec/system/summarization/topic_summarization_spec.rbindex b3d75880adf..dd6fc677eaa 100644--- a/plugins/discourse-ai/spec/system/summarization/topic_summarization_spec.rb+++ b/plugins/discourse-ai/spec/system/summarization/topic_summarization_spec.rb@@ -25,7 +25,7 @@ RSpec.describe "Summarize a topic ", type: :system dogroup.add(current_user)- assign_fake_provider_to(:ai_summarization_model)+ assign_fake_provider_to(:ai_default_llm_model)assign_persona_to(:ai_summarization_persona, [group.id])SiteSetting.ai_summarization_enabled = true