2024-05-05 19:49:02 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ::Jobs
|
|
|
|
class CreateAiChatReply < ::Jobs::Base
|
|
|
|
sidekiq_options retry: false
|
|
|
|
|
|
|
|
def execute(args)
|
|
|
|
channel = ::Chat::Channel.find_by(id: args[:channel_id])
|
|
|
|
return if channel.blank?
|
|
|
|
|
|
|
|
message = ::Chat::Message.find_by(id: args[:message_id])
|
|
|
|
return if message.blank?
|
|
|
|
|
|
|
|
personaClass =
|
|
|
|
DiscourseAi::AiBot::Personas::Persona.find_by(id: args[:persona_id], user: message.user)
|
|
|
|
return if personaClass.blank?
|
|
|
|
|
|
|
|
user = User.find_by(id: personaClass.user_id)
|
|
|
|
bot = DiscourseAi::AiBot::Bot.as(user, persona: personaClass.new)
|
|
|
|
|
2024-05-21 03:17:02 -04:00
|
|
|
DiscourseAi::AiBot::Playground.new(bot).reply_to_chat_message(
|
|
|
|
message,
|
|
|
|
channel,
|
|
|
|
args[:context_post_ids],
|
|
|
|
)
|
2024-05-05 19:49:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|