mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-07-01 20:12:15 +00:00
27 lines
813 B
Ruby
27 lines
813 B
Ruby
|
# 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
|