A platform for community discussion. Free, open, simple.
FIX: Ensure base_path is correctly inserted into LLM triage messages. (#34778)
Gary Pendergasta9bac35678b8
diff --git a/plugins/discourse-ai/config/locales/server.en.yml b/plugins/discourse-ai/config/locales/server.en.ymlindex c46e643fa84..a7e6d70b2f7 100644--- a/plugins/discourse-ai/config/locales/server.en.yml+++ b/plugins/discourse-ai/config/locales/server.en.yml@@ -19,8 +19,8 @@ en:description: "Triage posts using a large language model"flagged_post: |<div>Response from the model:</div>- <p>%%LLM_RESPONSE%%</p>- <b>Triggered by the <a href="%{base_path}/admin/plugins/discourse-automation/%%AUTOMATION_ID%%">%%AUTOMATION_NAME%%</a> rule.</b>+ <p>%{llm_response}</p>+ <b>Triggered by the <a href="%{base_path}/admin/plugins/discourse-automation/%{automation_id}">%{automation_name}</a> rule.</b>notify_author_pm:subject: "Your post was temporarily removed for review"body: |diff --git a/plugins/discourse-ai/lib/automation/llm_triage.rb b/plugins/discourse-ai/lib/automation/llm_triage.rbindex a693325ac03..529ed09a1d7 100644--- a/plugins/discourse-ai/lib/automation/llm_triage.rb+++ b/plugins/discourse-ai/lib/automation/llm_triage.rb@@ -134,11 +134,13 @@ module DiscourseAiif flag_postscore_reason =- I18n- .t("discourse_automation.scriptables.llm_triage.flagged_post")- .sub("%%LLM_RESPONSE%%", result)- .sub("%%AUTOMATION_ID%%", automation&.id.to_s)- .sub("%%AUTOMATION_NAME%%", automation&.name.to_s)+ I18n.t(+ "discourse_automation.scriptables.llm_triage.flagged_post",+ base_path: Discourse.base_path,+ llm_response: result,+ automation_id: automation&.id.to_s,+ automation_name: automation&.name.to_s,+ )if flag_type == :spam || flag_type == :spam_silenceresult =diff --git a/plugins/discourse-ai/spec/lib/modules/automation/llm_triage_spec.rb b/plugins/discourse-ai/spec/lib/modules/automation/llm_triage_spec.rbindex 0d2658c5419..97a55a844b0 100644--- a/plugins/discourse-ai/spec/lib/modules/automation/llm_triage_spec.rb+++ b/plugins/discourse-ai/spec/lib/modules/automation/llm_triage_spec.rb@@ -345,4 +345,25 @@ describe DiscourseAi::Automation::LlmTriage doexpect(post.topic.reload.tags).to contain_exactly(tag_1, tag_2)end++ it "includes the base path in the flagged post message" do+ allow(Discourse).to receive(:base_path).and_return("http://test.host")++ DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do+ triage(+ post: post,+ triage_persona_id: ai_persona.id,+ search_for_text: "bad",+ flag_post: true,+ automation: nil,+ )+ end++ reviewable = ReviewablePost.last+ expect(reviewable.target_id).to eq(post.id)+ expect(reviewable.target_type).to eq("Post")+ expect(reviewable.reviewable_scores.first.reason).to include(+ "<a href=\"#{Discourse.base_path}/admin/plugins/discourse-automation/",+ )+ endend