Class: Boxcars::ConversationPrompt
- Defined in:
- lib/boxcars/conversation_prompt.rb
Overview
used by Boxcars that have engine’s to create a conversation prompt.
Instance Attribute Summary collapse
-
#conversation ⇒ Object
readonly
Returns the value of attribute conversation.
Attributes inherited from Prompt
#input_variables, #other_inputs, #output_variables, #template
Instance Method Summary collapse
-
#add_history(history) ⇒ Object
add conversation history to the prompt.
-
#as_intelligence_conversation(inputs: nil) ⇒ Intelligence::Conversation
Convert the prompt to an Intelligence::Conversation.
-
#as_messages(inputs) ⇒ Hash
prompt for chatGPT params.
-
#as_prompt(inputs:, prefixes: default_prefixes, show_roles: false) ⇒ Hash
prompt for non chatGPT params.
- #default_prefixes ⇒ Object
-
#initialize(conversation:, input_variables: nil, other_inputs: nil, output_variables: nil) ⇒ ConversationPrompt
constructor
A new instance of ConversationPrompt.
-
#to_s ⇒ Object
print the prompt.
-
#with_conversation(conversation) ⇒ Object
tack on the ongoing conversation if present to the prompt.
Methods inherited from Prompt
Constructor Details
#initialize(conversation:, input_variables: nil, other_inputs: nil, output_variables: nil) ⇒ ConversationPrompt
Returns a new instance of ConversationPrompt.
12 13 14 15 |
# File 'lib/boxcars/conversation_prompt.rb', line 12 def initialize(conversation:, input_variables: nil, other_inputs: nil, output_variables: nil) @conversation = conversation super(template:, input_variables:, other_inputs:, output_variables:) end |
Instance Attribute Details
#conversation ⇒ Object (readonly)
Returns the value of attribute conversation.
6 7 8 |
# File 'lib/boxcars/conversation_prompt.rb', line 6 def conversation @conversation end |
Instance Method Details
#add_history(history) ⇒ Object
add conversation history to the prompt
42 43 44 |
# File 'lib/boxcars/conversation_prompt.rb', line 42 def add_history(history) conversation.add_history(Conversation.new(lines: history)) end |
#as_intelligence_conversation(inputs: nil) ⇒ Intelligence::Conversation
Convert the prompt to an Intelligence::Conversation
58 59 60 |
# File 'lib/boxcars/conversation_prompt.rb', line 58 def as_intelligence_conversation(inputs: nil) conversation.as_intelligence_conversation(inputs:) end |
#as_messages(inputs) ⇒ Hash
prompt for chatGPT params
20 21 22 |
# File 'lib/boxcars/conversation_prompt.rb', line 20 def (inputs) conversation.(inputs) end |
#as_prompt(inputs:, prefixes: default_prefixes, show_roles: false) ⇒ Hash
prompt for non chatGPT params
27 28 29 |
# File 'lib/boxcars/conversation_prompt.rb', line 27 def as_prompt(inputs:, prefixes: default_prefixes, show_roles: false) { prompt: conversation.as_prompt(inputs:, prefixes:, show_roles:) } end |
#default_prefixes ⇒ Object
51 52 53 |
# File 'lib/boxcars/conversation_prompt.rb', line 51 def default_prefixes conversation.default_prefixes end |
#to_s ⇒ Object
print the prompt
47 48 49 |
# File 'lib/boxcars/conversation_prompt.rb', line 47 def to_s conversation.to_s end |
#with_conversation(conversation) ⇒ Object
tack on the ongoing conversation if present to the prompt
32 33 34 35 36 37 38 |
# File 'lib/boxcars/conversation_prompt.rb', line 32 def with_conversation(conversation) return self unless conversation new_prompt = dup new_prompt.conversation.add_conversation(conversation) new_prompt end |