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

Commit 24b69bf

Browse files
authored
FIX: Update spam controller action should consider seeded LLM properly (#1053)
The seeded LLM setting: `SiteSetting.ai_spam_detection_model_allowed_seeded_models` returns a _string_ with IDs separated by pipes. running `_map` on it will return an array with strings. We were previously checking for the id with custom prefix identifier, but instead we should be checking the stringified ID.
1 parent 404092a commit 24b69bf

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

app/controllers/discourse_ai/admin/ai_spam_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def update
1515
llm_model_id = updated_params[:llm_model_id] = allowed_params[:llm_model_id]
1616
if llm_model_id.to_i < 0 &&
1717
!SiteSetting.ai_spam_detection_model_allowed_seeded_models_map.include?(
18-
"custom:#{llm_model_id}",
18+
llm_model_id.to_s,
1919
)
2020
return(
2121
render_json_error(

spec/requests/admin/ai_spam_controller_spec.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
expect(response.status).to eq(422)
3939

40-
SiteSetting.ai_spam_detection_model_allowed_seeded_models = seeded_llm.identifier
40+
SiteSetting.ai_spam_detection_model_allowed_seeded_models = seeded_llm.id.to_s
4141

4242
put "/admin/plugins/discourse-ai/ai-spam.json",
4343
params: {
@@ -49,6 +49,26 @@
4949
expect(response.status).to eq(200)
5050
end
5151

52+
it "ensures that seeded llm ID is properly passed and allowed" do
53+
seeded_llm = Fabricate(:seeded_model)
54+
55+
SiteSetting.ai_spam_detection_model_allowed_seeded_models = [
56+
llm_model.id,
57+
seeded_llm.id,
58+
].join("|")
59+
60+
put "/admin/plugins/discourse-ai/ai-spam.json",
61+
params: {
62+
is_enabled: true,
63+
llm_model_id: seeded_llm.id,
64+
custom_instructions: "custom instructions",
65+
}
66+
expect(SiteSetting.ai_spam_detection_model_allowed_seeded_models).to eq(
67+
"#{llm_model.id}|#{seeded_llm.id}",
68+
)
69+
expect(response.status).to eq(200)
70+
end
71+
5272
it "can not enable spam detection without a model selected" do
5373
put "/admin/plugins/discourse-ai/ai-spam.json",
5474
params: {

0 commit comments

Comments
 (0)