A platform for community discussion. Free, open, simple.
FIX: Attribute automation-triggered AI usage to system user
zogstrip6bd6fdd0cd50
diff --git a/plugins/discourse-ai/lib/ai_bot/playground.rb b/plugins/discourse-ai/lib/ai_bot/playground.rbindex f81aec146de..849816892e3 100644--- a/plugins/discourse-ai/lib/ai_bot/playground.rb+++ b/plugins/discourse-ai/lib/ai_bot/playground.rb@@ -191,7 +191,8 @@ module DiscourseAistream_reply: false,auto_set_title: false,silent_mode: false,- feature_name: nil+ feature_name: nil,+ attributed_user: nil)ai_persona = AiPersona.find_by(id: persona_id)raise Discourse::InvalidParameters.new(:persona_id) if !ai_persona@@ -212,6 +213,7 @@ module DiscourseAiauto_set_title: auto_set_title,silent_mode: silent_mode,feature_name: feature_name,+ attributed_user: attributed_user,)rescue => eif Rails.env.test?@@ -420,6 +422,7 @@ module DiscourseAifeature_name: nil,existing_reply_post: nil,cancel_manager: nil,+ attributed_user: nil,&blk)# this is a multithreading issue@@ -453,6 +456,7 @@ module DiscourseAicontext =DiscourseAi::Personas::BotContext.new(post: post,+ user: attributed_user,custom_instructions: custom_instructions,feature_name: feature_name,messages:diff --git a/plugins/discourse-ai/lib/automation/llm_persona_triage.rb b/plugins/discourse-ai/lib/automation/llm_persona_triage.rbindex dbbdbc6ae3e..2bde15509ba 100644--- a/plugins/discourse-ai/lib/automation/llm_persona_triage.rb+++ b/plugins/discourse-ai/lib/automation/llm_persona_triage.rb@@ -9,6 +9,7 @@ module DiscourseAiwhisper: whisper,silent_mode: silent_mode,feature_name: "automation - #{automation&.name}",+ attributed_user: Discourse.system_user,)rescue => eDiscourse.warn_exception(diff --git a/plugins/discourse-ai/lib/automation/llm_triage.rb b/plugins/discourse-ai/lib/automation/llm_triage.rbindex 9d240c69d9d..0bb83acdf15 100644--- a/plugins/discourse-ai/lib/automation/llm_triage.rb+++ b/plugins/discourse-ai/lib/automation/llm_triage.rb@@ -107,6 +107,7 @@ module DiscourseAipersona_id: reply_persona_id,whisper: whisper,user: original_user,+ attributed_user: Discourse.system_user,)rescue StandardError => eDiscourse.warn_exception(diff --git a/plugins/discourse-ai/spec/lib/discourse_automation/llm_persona_triage_spec.rb b/plugins/discourse-ai/spec/lib/discourse_automation/llm_persona_triage_spec.rbindex b60b12073d9..e91d1189539 100644--- a/plugins/discourse-ai/spec/lib/discourse_automation/llm_persona_triage_spec.rb+++ b/plugins/discourse-ai/spec/lib/discourse_automation/llm_persona_triage_spec.rb@@ -83,7 +83,7 @@ describe DiscourseAi::Automation::LlmPersonaTriage dolog = AiApiAuditLog.lastexpect(log).to be_present- expect(log.user_id).to eq(post.user_id)+ expect(log.user_id).to eq(Discourse.system_user.id)expect(log.feature_name).to eq("automation - #{automation.name}")topic = post.topic.reload