mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-08-03 19:53:28 +00:00
- add sleep function for tool polling with rate limits - Support base64 encoding for HTTP requests and uploads - Enhance forum researcher with cost warnings and comprehensive planning - Add cancellation support for research operations - Include feature_name parameter for bot analytics - richer research support (OR queries)
27 lines
874 B
Ruby
27 lines
874 B
Ruby
# frozen_string_literal: true
|
|
|
|
module ::Jobs
|
|
class CreateAiReply < ::Jobs::Base
|
|
sidekiq_options retry: false
|
|
|
|
def execute(args)
|
|
return unless bot_user = User.find_by(id: args[:bot_user_id])
|
|
return unless post = Post.includes(:topic).find_by(id: args[:post_id])
|
|
persona_id = args[:persona_id]
|
|
|
|
begin
|
|
persona = DiscourseAi::Personas::Persona.find_by(user: post.user, id: persona_id)
|
|
raise DiscourseAi::Personas::Bot::BOT_NOT_FOUND if persona.nil?
|
|
|
|
bot = DiscourseAi::Personas::Bot.as(bot_user, persona: persona.new)
|
|
|
|
DiscourseAi::AiBot::Playground.new(bot).reply_to(post, feature_name: "bot")
|
|
rescue DiscourseAi::Personas::Bot::BOT_NOT_FOUND
|
|
Rails.logger.warn(
|
|
"Bot not found for post #{post.id} - perhaps persona was deleted or bot was disabled",
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|