Module: Raix::PromptDeclarations::ClassMethods
- Defined in:
- lib/raix/prompt_declarations.rb
Overview
rubocop:disable Style/Documentation
Instance Method Summary collapse
-
#prompt(text:, system: nil, success: nil, params: {}) ⇒ Object
Adds a prompt to the list of prompts.
-
#prompts ⇒ Object
the list of prompts declared at class level.
-
#system_prompt(prompt = nil) ⇒ Object
getter/setter for system prompt declared at class level.
Instance Method Details
#prompt(text:, system: nil, success: nil, params: {}) ⇒ Object
Adds a prompt to the list of prompts.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/raix/prompt_declarations.rb', line 20 def prompt(text:, system: nil, success: nil, params: {}) name = Digest::SHA256.hexdigest(text.inspect)[0..7] prompts << begin OpenStruct.new({ name:, system:, text:, success:, params: }) end define_method(name) do |response| if Rails.env.local? puts "_" * 80 puts "PromptDeclarations#response:" puts "#{text.source_location} (#{name})" puts response puts "_" * 80 end return response if success.nil? return send(success, response) if success.is_a?(Symbol) instance_exec(response, &success) end end |
#prompts ⇒ Object
the list of prompts declared at class level
43 44 45 |
# File 'lib/raix/prompt_declarations.rb', line 43 def prompts @prompts ||= [] end |
#system_prompt(prompt = nil) ⇒ Object
getter/setter for system prompt declared at class level
48 49 50 |
# File 'lib/raix/prompt_declarations.rb', line 48 def system_prompt(prompt = nil) prompt ? @system_prompt = prompt.squish : @system_prompt end |