Class: ActiveAgent::ActionPrompt::Prompt

Inherits:
Object
  • Object
show all
Defined in:
lib/active_agent/action_prompt/prompt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, [])

  set_message if attributes[:message].is_a?(String) || @body.is_a?(String) && @message.content
  set_messages if @messages.any? || @instructions.present?
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



7
8
9
# File 'lib/active_agent/action_prompt/prompt.rb', line 7

def actions
  @actions
end

#bodyObject

Returns the value of attribute body.



7
8
9
# File 'lib/active_agent/action_prompt/prompt.rb', line 7

def body
  @body
end

#charsetObject

Returns the value of attribute charset.



7
8
9
# File 'lib/active_agent/action_prompt/prompt.rb', line 7

def charset
  @charset
end

#content_typeObject

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

#contextObject

Returns the value of attribute context.



7
8
9
# File 'lib/active_agent/action_prompt/prompt.rb', line 7

def context
  @context
end

#instructionsObject

Returns the value of attribute instructions.



7
8
9
# File 'lib/active_agent/action_prompt/prompt.rb', line 7

def instructions
  @instructions
end

#messageObject

Returns the value of attribute message.



7
8
9
# File 'lib/active_agent/action_prompt/prompt.rb', line 7

def message
  @message
end

#messagesObject

Returns the value of attribute messages.



7
8
9
# File 'lib/active_agent/action_prompt/prompt.rb', line 7

def messages
  @messages
end

#mime_versionObject

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

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/active_agent/action_prompt/prompt.rb', line 7

def options
  @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 = Message.new(content: part[:body], role: :user)
  prompt_part = self.class.new(message: message, content: message.content, content_type: part[:content_type], chartset: part[:charset])

  set_message 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

Returns:

  • (Boolean)


43
44
45
# File 'lib/active_agent/action_prompt/prompt.rb', line 43

def multipart?
  @parts.any?
end

#to_hObject



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_sObject

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