Module: RailsAIPromptable::Promptable

Extended by:
ActiveSupport::Concern
Defined in:
lib/rails_ai_promptable/promptable.rb

Instance Method Summary collapse

Instance Method Details

#ai_generate(context: {}, model: nil, temperature: nil, format: :text) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rails_ai_promptable/promptable.rb', line 33

def ai_generate(context: {}, model: nil, temperature: nil, format: :text)
  template = self.class.ai_prompt_template || ""
  prompt = render_template(template, context)

  RailsAIPromptable.configuration.logger.info("[rails_ai_promptable] prompt: ")

  RailsAIPromptable.client.generate(
    prompt: prompt,
    model: model || RailsAIPromptable.configuration.default_model,
    temperature: temperature || 0.7,
    format: format
  )

  # basic parsing
end

#ai_generate_later(context: {}, **kwargs) ⇒ Object



49
50
51
52
53
# File 'lib/rails_ai_promptable/promptable.rb', line 49

def ai_generate_later(context: {}, **kwargs)
  RailsAIPromptable.configuration.logger.info("[rails_ai_promptable] enqueuing ai_generate_later")
  # Use ActiveJob to enqueue. We'll provide a default job class in later steps.
  RailsAIPromptable::BackgroundJob.perform_later(self.class.name, id, context, kwargs)
end