DEV: Only permit config of allowed seeded models (#1103)

This update resolves a regression that was introduced in https://github.com/discourse/discourse-ai/pull/1036/files. Previously, only seeded models that were allowed could be configured for model settings. However, in our attempts to prevent unreachable LLM errors from not allowing settings to persist, it also unknowingly allowed seeded models that were not allowed to be configured. This update resolves this issue, while maintaining the ability to still set unreachable LLMs.
This commit is contained in:
Keegan George 2025-02-01 06:01:15 +09:00 committed by GitHub
parent 980f17a338
commit 13f9a1908a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,9 @@
module DiscourseAi
module Configuration
class InvalidSeededModelError < StandardError
end
class LlmValidator
def initialize(opts = {})
@opts = opts
@ -18,8 +21,12 @@ module DiscourseAi
allowed_seeded_model?(val)
run_test(val).tap { |result| @unreachable = result }
rescue DiscourseAi::Configuration::InvalidSeededModelError => e
@unreachable = true
false
rescue StandardError => e
raise e if Rails.env.test?
@unreachable = true
true
end
@ -76,7 +83,7 @@ module DiscourseAi
if allowed_list.split("|").exclude?(id)
@invalid_seeded_model = true
raise Discourse::InvalidParameters.new
raise DiscourseAi::Configuration::InvalidSeededModelError.new
end
end
end