Class: ActiveAgent::ActionPrompt::Prompt
- Inherits:
-
Object
- Object
- ActiveAgent::ActionPrompt::Prompt
- Defined in:
- lib/active_agent/action_prompt/prompt.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#body ⇒ Object
Returns the value of attribute body.
-
#charset ⇒ Object
Returns the value of attribute charset.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#context ⇒ Object
Returns the value of attribute context.
-
#instructions ⇒ Object
Returns the value of attribute instructions.
-
#message ⇒ Object
Returns the value of attribute message.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#mime_version ⇒ Object
Returns the value of attribute mime_version.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parts ⇒ Object
Returns the value of attribute parts.
Instance Method Summary collapse
- #add_part(prompt_part) ⇒ Object
- #headers(headers = {}) ⇒ Object
-
#initialize(attributes = {}) ⇒ Prompt
constructor
A new instance of Prompt.
- #multipart? ⇒ Boolean
- #to_h ⇒ Object
-
#to_s ⇒ Object
Generate the prompt as a string (for debugging or sending to the provider).
Constructor Details
#initialize(attributes = {}) ⇒ Prompt
Returns a new instance of Prompt.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 8 def initialize(attributes = {}) @options = attributes.fetch(:options, {}) @actions = attributes.fetch(:actions, []) @action_choice = attributes.fetch(:action_choice, "") @instructions = attributes.fetch(:instructions, "") @body = attributes.fetch(:body, "") @content_type = attributes.fetch(:content_type, "text/plain") @message = attributes.fetch(:message, Message.new) @messages = attributes.fetch(:messages, []) @params = attributes.fetch(:params, {}) @mime_version = attributes.fetch(:mime_version, "1.0") @charset = attributes.fetch(:charset, "UTF-8") @context = attributes.fetch(:context, []) @headers = attributes.fetch(:headers, {}) @parts = attributes.fetch(:parts, []) if attributes[:message].is_a?(String) || @body.is_a?(String) && @message.content if @messages.any? || @instructions.present? end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
6 7 8 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 6 def actions @actions end |
#body ⇒ Object
Returns the value of attribute body.
6 7 8 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 6 def body @body end |
#charset ⇒ Object
Returns the value of attribute charset.
6 7 8 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 6 def charset @charset end |
#content_type ⇒ Object
Returns the value of attribute content_type.
6 7 8 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 6 def content_type @content_type end |
#context ⇒ Object
Returns the value of attribute context.
6 7 8 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 6 def context @context end |
#instructions ⇒ Object
Returns the value of attribute instructions.
6 7 8 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 6 def instructions @instructions end |
#message ⇒ Object
Returns the value of attribute message.
6 7 8 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 6 def @message end |
#messages ⇒ Object
Returns the value of attribute messages.
6 7 8 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 6 def @messages end |
#mime_version ⇒ Object
Returns the value of attribute mime_version.
6 7 8 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 6 def mime_version @mime_version end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 6 def @options end |
#parts ⇒ Object
Returns the value of attribute parts.
6 7 8 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 6 def parts @parts end |
Instance Method Details
#add_part(prompt_part) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 33 def add_part(prompt_part) @message = prompt_part. if @content_type == prompt_part.content_type && @message.content.present? @parts << prompt_part end |
#headers(headers = {}) ⇒ Object
57 58 59 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 57 def headers(headers = {}) @headers.merge!(headers) end |
#multipart? ⇒ Boolean
41 42 43 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 41 def multipart? @parts.any? end |
#to_h ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 45 def to_h { actions: @actions, action: @action_choice, instructions: @instructions, message: @message.to_h, messages: @messages.map(&:to_h), headers: @headers, context: @context } end |
#to_s ⇒ Object
Generate the prompt as a string (for debugging or sending to the provider)
29 30 31 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 29 def to_s @message.to_s end |