generated from discourse/discourse-plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is far simpler to configure than using custom tools
- Loading branch information
1 parent
568685c
commit 94658cd
Showing
11 changed files
with
402 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
if defined?(DiscourseAutomation) | ||
DiscourseAutomation::Scriptable.add("llm_persona_triage") do | ||
version 1 | ||
run_in_background | ||
|
||
triggerables %i[post_created_edited] | ||
|
||
field :persona, | ||
component: :choices, | ||
required: true, | ||
extra: { | ||
content: DiscourseAi::Automation.available_persona_choices, | ||
} | ||
field :whisper, component: :boolean | ||
|
||
script do |context, fields| | ||
post = context["post"] | ||
next if post&.user&.bot? | ||
|
||
persona_id = fields["persona"]["value"] | ||
whisper = fields["whisper"]["value"] | ||
|
||
begin | ||
RateLimiter.new( | ||
Discourse.system_user, | ||
"llm_persona_triage_#{post.id}", | ||
SiteSetting.ai_automation_max_triage_per_post_per_minute, | ||
1.minute, | ||
).performed! | ||
|
||
RateLimiter.new( | ||
Discourse.system_user, | ||
"llm_persona_triage", | ||
SiteSetting.ai_automation_max_triage_per_minute, | ||
1.minute, | ||
).performed! | ||
|
||
DiscourseAi::Automation::LlmPersonaTriage.handle( | ||
post: post, | ||
persona_id: persona_id, | ||
whisper: whisper, | ||
automation: self.automation, | ||
) | ||
rescue => e | ||
Discourse.warn_exception( | ||
e, | ||
message: "llm_persona_triage: skipped triage on post #{post.id}", | ||
) | ||
raise e if Rails.env.tests? | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
module DiscourseAi | ||
module Automation | ||
module LlmPersonaTriage | ||
def self.handle(post:, persona_id:, whisper: false, automation: nil) | ||
ai_persona = AiPersona.find_by(id: persona_id) | ||
return if ai_persona.nil? | ||
|
||
persona_class = ai_persona.class_instance | ||
persona = persona_class.new | ||
|
||
bot_user = ai_persona.user | ||
return if bot_user.nil? | ||
|
||
bot = DiscourseAi::AiBot::Bot.as(bot_user, persona: persona) | ||
playground = DiscourseAi::AiBot::Playground.new(bot) | ||
|
||
playground.reply_to(post, whisper: whisper, context_style: :topic) | ||
rescue => e | ||
Rails.logger.error("Error in LlmPersonaTriage: #{e.message}\n#{e.backtrace.join("\n")}") | ||
raise e if Rails.env.test? | ||
nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.