From 13f9a1908a2a8d8710446a6d47cf9587013e3689 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Sat, 1 Feb 2025 06:01:15 +0900 Subject: [PATCH] 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. --- lib/configuration/llm_validator.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/configuration/llm_validator.rb b/lib/configuration/llm_validator.rb index 44d94b33..2ba98421 100644 --- a/lib/configuration/llm_validator.rb +++ b/lib/configuration/llm_validator.rb @@ -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