14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/rails_ai_promptable/background_job.rb', line 14
def perform(klass_name, record_id, context, kwargs)
klass = klass_name.constantize
record = klass.find_by(id: record_id)
return unless record
result = record.ai_generate(context: context, **(kwargs || {}))
record.ai_generation_completed(result) if record.respond_to?(:ai_generation_completed)
if record.respond_to?(:ai_generated_content=)
record.ai_generated_content = result
record.save if record.respond_to?(:save)
end
RailsAIPromptable.configuration.logger.info("[rails_ai_promptable] background generation completed for #{klass_name}##{record_id}")
result
end
|