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.
Instance Method Summary collapse
- #add_part(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.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 9 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.
7 8 9 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 7 def actions @actions end |
#body ⇒ Object
Returns the value of attribute body.
7 8 9 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 7 def body @body end |
#charset ⇒ Object
Returns the value of attribute charset.
7 8 9 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 7 def charset @charset end |
#content_type ⇒ Object
Returns the value of attribute content_type.
7 8 9 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 7 def content_type @content_type end |
#context ⇒ Object
Returns the value of attribute context.
7 8 9 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 7 def context @context end |
#instructions ⇒ Object
Returns the value of attribute instructions.
7 8 9 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 7 def instructions @instructions end |
#message ⇒ Object
Returns the value of attribute message.
7 8 9 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 7 def @message end |
#messages ⇒ Object
Returns the value of attribute messages.
7 8 9 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 7 def @messages end |
#mime_version ⇒ Object
Returns the value of attribute mime_version.
7 8 9 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 7 def mime_version @mime_version end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 7 def @options end |
Instance Method Details
#add_part(part) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 34 def add_part(part) = Message.new(content: part[:body], role: :user) prompt_part = self.class.new(message: , content: .content, content_type: part[:content_type], chartset: part[:charset]) if @content_type == part[:content_type] && @message.content @parts << prompt_part end |
#headers(headers = {}) ⇒ Object
59 60 61 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 59 def headers(headers = {}) @headers.merge!(headers) end |
#multipart? ⇒ Boolean
43 44 45 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 43 def multipart? @parts.any? end |
#to_h ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 47 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)
30 31 32 |
# File 'lib/active_agent/action_prompt/prompt.rb', line 30 def to_s @message.to_s end |