Class: ActionPrompt::Message
- Inherits:
-
Object
- Object
- ActionPrompt::Message
- Defined in:
- lib/action_prompt/message.rb
Overview
Represents a fully prepared prompt ready for delivery to an LLM adapter.
Analogous to Mail::Message in ActionMailer.
Instances are returned by calling a class-level action method:
= ArticleSummarizerPrompt.summarize(article)
.body # => rendered ERB string (lazily evaluated)
.deliver_now # => LLM response string
Instance Attribute Summary collapse
-
#action_name ⇒ String
readonly
The name of the action that built this message.
-
#options ⇒ Hash
readonly
Merged LLM options (global defaults < class defaults < per-action options).
-
#prompt_instance ⇒ ActionPrompt::Base
readonly
The prompt instance that built this message.
Instance Method Summary collapse
-
#body ⇒ String
The rendered prompt body.
-
#deliver_later(**_kwargs) ⇒ Object
Enqueues the prompt for asynchronous delivery via ActiveJob.
-
#deliver_now ⇒ String?
Delivers the prompt to the configured adapter synchronously and returns the LLM response.
-
#initialize(prompt_instance, action_name, options = {}) ⇒ Message
constructor
A new instance of Message.
- #inspect ⇒ String (also: #to_s)
Constructor Details
#initialize(prompt_instance, action_name, options = {}) ⇒ Message
28 29 30 31 32 |
# File 'lib/action_prompt/message.rb', line 28 def initialize(prompt_instance, action_name, = {}) @prompt_instance = prompt_instance @action_name = action_name = end |
Instance Attribute Details
#action_name ⇒ String (readonly)
The name of the action that built this message.
19 20 21 |
# File 'lib/action_prompt/message.rb', line 19 def action_name @action_name end |
#options ⇒ Hash (readonly)
Merged LLM options (global defaults < class defaults < per-action options).
23 24 25 |
# File 'lib/action_prompt/message.rb', line 23 def end |
#prompt_instance ⇒ ActionPrompt::Base (readonly)
The prompt instance that built this message.
15 16 17 |
# File 'lib/action_prompt/message.rb', line 15 def prompt_instance @prompt_instance end |
Instance Method Details
#body ⇒ String
The rendered prompt body. Evaluated lazily on first access.
37 38 39 |
# File 'lib/action_prompt/message.rb', line 37 def body @body ||= Renderer.new(prompt_instance, action_name).render end |
#deliver_later(**_kwargs) ⇒ Object
Full ActiveJob integration is planned for a future release.
This currently raises NotImplementedError.
Enqueues the prompt for asynchronous delivery via ActiveJob.
55 56 57 58 59 |
# File 'lib/action_prompt/message.rb', line 55 def deliver_later(**_kwargs) raise NotImplementedError, "deliver_later is not yet implemented. Use deliver_now. " \ "ActiveJob integration is planned for a future release." end |
#deliver_now ⇒ String?
Delivers the prompt to the configured adapter synchronously and returns the LLM response.
45 46 47 48 |
# File 'lib/action_prompt/message.rb', line 45 def deliver_now log_delivery ActionPrompt.configuration.adapter.complete(body, ) end |
#inspect ⇒ String Also known as: to_s
62 63 64 |
# File 'lib/action_prompt/message.rb', line 62 def inspect "#<ActionPrompt::Message action=#{action_name.inspect} options=#{options.inspect}>" end |