diff --git a/app/controllers/discourse_ai/admin/ai_llms_controller.rb b/app/controllers/discourse_ai/admin/ai_llms_controller.rb index ad6ff6b4..243b0a2b 100644 --- a/app/controllers/discourse_ai/admin/ai_llms_controller.rb +++ b/app/controllers/discourse_ai/admin/ai_llms_controller.rb @@ -45,6 +45,10 @@ module DiscourseAi def update llm_model = LlmModel.find(params[:id]) + if llm_model.seeded? + return render_json_error(I18n.t("discourse_ai.llm.cannot_edit_builtin"), status: 403) + end + if llm_model.update(ai_llm_params(updating: llm_model)) llm_model.toggle_companion_user render json: LlmModelSerializer.new(llm_model) @@ -56,6 +60,10 @@ module DiscourseAi def destroy llm_model = LlmModel.find(params[:id]) + if llm_model.seeded? + return 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) if !in_use_by.empty? diff --git a/app/models/llm_model.rb b/app/models/llm_model.rb index c1c7ef7a..c411fb14 100644 --- a/app/models/llm_model.rb +++ b/app/models/llm_model.rb @@ -89,6 +89,10 @@ class LlmModel < ActiveRecord::Base provider_params&.dig(key) end + def seeded? + id < 0 + end + private def required_provider_params diff --git a/app/serializers/llm_model_serializer.rb b/app/serializers/llm_model_serializer.rb index ca852409..d515ca62 100644 --- a/app/serializers/llm_model_serializer.rb +++ b/app/serializers/llm_model_serializer.rb @@ -21,4 +21,16 @@ class LlmModelSerializer < ApplicationSerializer def used_by DiscourseAi::Configuration::LlmValidator.new.modules_using(object) end + + def api_key + object.seeded? ? "********" : object.api_key + end + + def url + object.seeded? ? "********" : object.url + end + + def provider + object.seeded? ? "CDCK" : object.provider + end end diff --git a/assets/javascripts/discourse/components/ai-llm-editor-form.gjs b/assets/javascripts/discourse/components/ai-llm-editor-form.gjs index 028662c4..1281481c 100644 --- a/assets/javascripts/discourse/components/ai-llm-editor-form.gjs +++ b/assets/javascripts/discourse/components/ai-llm-editor-form.gjs @@ -62,6 +62,10 @@ export default class AiLlmEditorForm extends Component { return this.args.model.used_by?.join(", "); } + get seeded() { + return this.args.model.id < 0; + } + get inUseWarning() { return I18n.t("discourse_ai.llms.in_use_warning", { settings: this.modulesUsingModel, @@ -170,13 +174,19 @@ export default class AiLlmEditorForm extends Component { }