FEATURE: safeguard to avoid over triage (#626)

- a post can be triaged a maximum of twice a minute
- system can run a total of 60 triages a minute

Low defaults were picked to safeguard against any possible loops

This can be amended if required via hidden site settings.
This commit is contained in:
Sam 2024-05-16 16:49:44 +10:00 committed by GitHub
parent d64cff7692
commit 255139056d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -358,3 +358,9 @@ discourse_ai:
ai_bot_github_access_token: ai_bot_github_access_token:
default: "" default: ""
secret: true secret: true
ai_automation_max_triage_per_minute:
default: 60
hidden: true
ai_automation_max_triage_per_post_per_minute:
default: 2
hidden: true

View File

@ -53,6 +53,20 @@ if defined?(DiscourseAutomation)
flag_post = fields.dig("flag_post", "value") flag_post = fields.dig("flag_post", "value")
begin begin
RateLimiter.new(
Discourse.system_user,
"llm_triage_#{post.id}",
SiteSetting.ai_automation_max_triage_per_post_per_minute,
1.minute,
).performed!
RateLimiter.new(
Discourse.system_user,
"llm_triage",
SiteSetting.ai_automation_max_triage_per_minute,
1.minute,
).performed!
DiscourseAi::Automation::LlmTriage.handle( DiscourseAi::Automation::LlmTriage.handle(
post: post, post: post,
model: model, model: model,
@ -66,7 +80,7 @@ if defined?(DiscourseAutomation)
flag_post: flag_post, flag_post: flag_post,
) )
rescue => e rescue => e
Discourse.warn_exception(e, message: "llm_triage: failed to run inference") Discourse.warn_exception(e, message: "llm_triage: skipped triage on post #{post.id}")
end end
end end
end end