Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 249aab1

Browse files
committed
DEV: Use a simple validator
- no need for seeding checks or module dependant checks
1 parent 5a29074 commit 249aab1

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

config/settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ discourse_ai:
1616
type: enum
1717
allow_any: false
1818
enum: "DiscourseAi::Configuration::LlmEnumerator"
19-
validator: "DiscourseAi::Configuration::LlmValidator"
19+
validator: "DiscourseAi::Configuration::SimpleLlmValidator"
2020

2121
ai_sentiment_enabled:
2222
default: false
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
module DiscourseAi
4+
module Configuration
5+
class SimpleLlmValidator
6+
def initialize(opts = {})
7+
@opts = opts
8+
end
9+
10+
def valid_value?(val)
11+
return true if val == ""
12+
13+
run_test(val).tap { |result| @unreachable = result }
14+
rescue StandardError => e
15+
raise e if Rails.env.test?
16+
@unreachable = true
17+
true
18+
end
19+
20+
def run_test(val)
21+
DiscourseAi::Completions::Llm
22+
.proxy(val)
23+
.generate("How much is 1 + 1?", user: nil, feature_name: "llm_validator")
24+
.present?
25+
end
26+
27+
def error_message
28+
return unless @unreachable
29+
30+
I18n.t("discourse_ai.llm.configuration.model_unreachable")
31+
end
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)