Class: Boxcars::Prompt
- Inherits:
-
Object
- Object
- Boxcars::Prompt
- Defined in:
- lib/boxcars/prompt.rb
Overview
used by Boxcars that have engine’s to create a prompt.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#input_variables ⇒ Object
readonly
Returns the value of attribute input_variables.
-
#other_inputs ⇒ Object
readonly
Returns the value of attribute other_inputs.
-
#output_variables ⇒ Object
readonly
Returns the value of attribute output_variables.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
-
#as_messages(inputs) ⇒ Hash
compute the prompt parameters with input substitutions.
-
#as_prompt(inputs: nil, prefixes: nil, show_roles: nil) ⇒ Hash
compute the prompt parameters with input substitutions (used for chatGPT) rubocop:disable Lint/UnusedMethodArgument.
- #default_prefixes ⇒ Object
-
#initialize(template:, input_variables: nil, other_inputs: nil, output_variables: nil) ⇒ Prompt
constructor
A new instance of Prompt.
-
#with_conversation(conversation) ⇒ Object
tack on the ongoing conversation if present to the prompt.
Constructor Details
#initialize(template:, input_variables: nil, other_inputs: nil, output_variables: nil) ⇒ Prompt
Returns a new instance of Prompt.
12 13 14 15 16 17 |
# File 'lib/boxcars/prompt.rb', line 12 def initialize(template:, input_variables: nil, other_inputs: nil, output_variables: nil) @template = template @input_variables = input_variables || [:input] @other_inputs = other_inputs || [] @output_variables = output_variables || [:output] end |
Instance Attribute Details
#input_variables ⇒ Object (readonly)
Returns the value of attribute input_variables.
6 7 8 |
# File 'lib/boxcars/prompt.rb', line 6 def input_variables @input_variables end |
#other_inputs ⇒ Object (readonly)
Returns the value of attribute other_inputs.
6 7 8 |
# File 'lib/boxcars/prompt.rb', line 6 def other_inputs @other_inputs end |
#output_variables ⇒ Object (readonly)
Returns the value of attribute output_variables.
6 7 8 |
# File 'lib/boxcars/prompt.rb', line 6 def output_variables @output_variables end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
6 7 8 |
# File 'lib/boxcars/prompt.rb', line 6 def template @template end |
Instance Method Details
#as_messages(inputs) ⇒ Hash
compute the prompt parameters with input substitutions
31 32 33 |
# File 'lib/boxcars/prompt.rb', line 31 def (inputs) { messages: [{ role: :user, content: format(inputs) }] } end |
#as_prompt(inputs: nil, prefixes: nil, show_roles: nil) ⇒ Hash
compute the prompt parameters with input substitutions (used for chatGPT) rubocop:disable Lint/UnusedMethodArgument
23 24 25 |
# File 'lib/boxcars/prompt.rb', line 23 def as_prompt(inputs: nil, prefixes: nil, show_roles: nil) { prompt: format(inputs) } end |
#default_prefixes ⇒ Object
44 45 |
# File 'lib/boxcars/prompt.rb', line 44 def default_prefixes end |
#with_conversation(conversation) ⇒ Object
tack on the ongoing conversation if present to the prompt
36 37 38 39 40 41 42 |
# File 'lib/boxcars/prompt.rb', line 36 def with_conversation(conversation) return self unless conversation new_prompt = dup new_prompt.template += "\n\n#{conversation.}" new_prompt end |