mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-06-29 19:12:15 +00:00
## 🔍 Overview This update re-introduces the validator used on the `ai_spam_detection_enabled` setting. It was initially added here: https://github.com/discourse/discourse-ai/pull/1374 to prevent Spam from being enabled without creating an `AiModerationSetting` value in the database. However, due to issues with backups/migrations we temporarily removed it here: https://github.com/discourse/discourse-ai/pull/1393. Now with some internal fixes, we can re-introduce it. We also update the validator so that it only validates when trying to turn on rather than when turning off too.
67 lines
1.8 KiB
Ruby
67 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe DiscourseAi::Configuration::LlmEnumerator do
|
|
fab!(:fake_model)
|
|
fab!(:llm_model)
|
|
fab!(:seeded_model)
|
|
fab!(:automation) do
|
|
Fabricate(:automation, script: "llm_report", name: "some automation", enabled: true)
|
|
end
|
|
|
|
describe "#values_for_serialization" do
|
|
it "returns an array for that can be used for serialization" do
|
|
fake_model.destroy!
|
|
|
|
expect(described_class.values_for_serialization).to eq(
|
|
[
|
|
{
|
|
id: llm_model.id,
|
|
name: llm_model.display_name,
|
|
vision_enabled: llm_model.vision_enabled,
|
|
},
|
|
],
|
|
)
|
|
|
|
expect(
|
|
described_class.values_for_serialization(allowed_seeded_llm_ids: [seeded_model.id.to_s]),
|
|
).to contain_exactly(
|
|
{
|
|
id: seeded_model.id,
|
|
name: seeded_model.display_name,
|
|
vision_enabled: seeded_model.vision_enabled,
|
|
},
|
|
{
|
|
id: llm_model.id,
|
|
name: llm_model.display_name,
|
|
vision_enabled: llm_model.vision_enabled,
|
|
},
|
|
)
|
|
end
|
|
end
|
|
|
|
describe "#global_usage" do
|
|
it "returns a hash of Llm models in use globally" do
|
|
SiteSetting.ai_helper_model = "custom:#{fake_model.id}"
|
|
SiteSetting.ai_helper_enabled = true
|
|
expect(described_class.global_usage).to eq(fake_model.id => [{ type: :ai_helper }])
|
|
end
|
|
|
|
it "returns information about automation rules" do
|
|
automation.fields.create!(
|
|
component: "text",
|
|
name: "model",
|
|
metadata: {
|
|
value: "custom:#{fake_model.id}",
|
|
},
|
|
target: "script",
|
|
)
|
|
|
|
usage = described_class.global_usage
|
|
|
|
expect(usage).to eq(
|
|
{ fake_model.id => [{ type: :automation, name: "some automation", id: automation.id }] },
|
|
)
|
|
end
|
|
end
|
|
end
|