Files
discourse-ai/lib/configuration/embedding_defs_validator.rb
T
Roman Rizzi 1572068735 DEV: Improve embedding configs validations (#1101)
Before this change, we let you set the embeddings selected model back to " " even with embeddings enabled. This will leave the site in a broken state.

Additionally, it adds a fail-safe for these scenarios to avoid errors on the topics page.
2025-01-30 14:16:56 -03:00

29 lines
706 B
Ruby

# frozen_string_literal: true
module DiscourseAi
module Configuration
class EmbeddingDefsValidator
def initialize(opts = {})
@opts = opts
end
def valid_value?(val)
if val.blank?
@module_enabled = SiteSetting.ai_embeddings_enabled
!@module_enabled
else
EmbeddingDefinition.exists?(id: val).tap { |def_exists| @invalid_option = !def_exists }
end
end
def error_message
return I18n.t("discourse_ai.embeddings.configuration.disable_embeddings") if @module_enabled
return I18n.t("discourse_ai.embeddings.configuration.invalid_config") if @invalid_option
""
end
end
end
end