2023-03-15 17:21:45 -03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
|
|
|
class GenerateEmbeddings < ::Jobs::Base
|
|
|
|
def execute(args)
|
|
|
|
return unless SiteSetting.ai_embeddings_enabled
|
|
|
|
return if (topic_id = args[:topic_id]).blank?
|
|
|
|
|
|
|
|
topic = Topic.find_by_id(topic_id)
|
|
|
|
return if topic.nil? || topic.private_message? && !SiteSetting.ai_embeddings_generate_for_pms
|
2023-03-31 16:15:10 -03:00
|
|
|
post = topic.first_post
|
2023-03-15 17:21:45 -03:00
|
|
|
return if post.nil? || post.raw.blank?
|
|
|
|
|
2023-07-13 12:41:36 -03:00
|
|
|
DiscourseAi::Embeddings::Manager.new(topic).generate!
|
2023-03-15 17:21:45 -03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|