Class: Qualspec::Suite::Definition
- Inherits:
-
Object
- Object
- Qualspec::Suite::Definition
- Defined in:
- lib/qualspec/suite/dsl.rb
Instance Attribute Summary collapse
-
#candidates_list ⇒ Object
readonly
Returns the value of attribute candidates_list.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#scenarios_list ⇒ Object
readonly
Returns the value of attribute scenarios_list.
-
#temperature_list ⇒ Object
readonly
Returns the value of attribute temperature_list.
-
#variants_config ⇒ Object
readonly
Returns the value of attribute variants_config.
Instance Method Summary collapse
-
#behaves_like(behavior_name) ⇒ Object
(also: #it_behaves_like, #include_behavior)
DSL: include shared behaviors.
- #candidate(name, model:, system_prompt: nil, **options) ⇒ Object
-
#candidates(&block) ⇒ Object
DSL: define candidates.
-
#initialize(name, &block) ⇒ Definition
constructor
A new instance of Definition.
-
#scenario(name, &block) ⇒ Object
DSL: define scenarios.
-
#temperatures(temps) ⇒ Object
DSL: define temperatures to test across.
-
#variants(factory: :prompt_variant, &block) ⇒ Object
DSL: configure variants using FactoryBot.
Constructor Details
#initialize(name, &block) ⇒ Definition
Returns a new instance of Definition.
8 9 10 11 12 13 14 15 16 |
# File 'lib/qualspec/suite/dsl.rb', line 8 def initialize(name, &block) @name = name @candidates_list = [] @scenarios_list = [] @variants_config = nil @temperature_list = [nil] # nil means use model default instance_eval(&block) if block_given? # rubocop:disable Style/EvalWithLocation -- DSL pattern requires eval end |
Instance Attribute Details
#candidates_list ⇒ Object (readonly)
Returns the value of attribute candidates_list.
6 7 8 |
# File 'lib/qualspec/suite/dsl.rb', line 6 def candidates_list @candidates_list end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/qualspec/suite/dsl.rb', line 6 def name @name end |
#scenarios_list ⇒ Object (readonly)
Returns the value of attribute scenarios_list.
6 7 8 |
# File 'lib/qualspec/suite/dsl.rb', line 6 def scenarios_list @scenarios_list end |
#temperature_list ⇒ Object (readonly)
Returns the value of attribute temperature_list.
6 7 8 |
# File 'lib/qualspec/suite/dsl.rb', line 6 def temperature_list @temperature_list end |
#variants_config ⇒ Object (readonly)
Returns the value of attribute variants_config.
6 7 8 |
# File 'lib/qualspec/suite/dsl.rb', line 6 def variants_config @variants_config end |
Instance Method Details
#behaves_like(behavior_name) ⇒ Object Also known as: it_behaves_like, include_behavior
DSL: include shared behaviors
63 64 65 66 |
# File 'lib/qualspec/suite/dsl.rb', line 63 def behaves_like(behavior_name) behavior = Behavior.find(behavior_name) @scenarios_list.concat(behavior.scenarios_list) end |
#candidate(name, model:, system_prompt: nil, **options) ⇒ Object
23 24 25 |
# File 'lib/qualspec/suite/dsl.rb', line 23 def candidate(name, model:, system_prompt: nil, **) @candidates_list << Candidate.new(name, model: model, system_prompt: system_prompt, **) end |
#candidates(&block) ⇒ Object
DSL: define candidates
19 20 21 |
# File 'lib/qualspec/suite/dsl.rb', line 19 def candidates(&block) instance_eval(&block) # rubocop:disable Style/EvalWithLocation -- DSL pattern requires eval end |
#scenario(name, &block) ⇒ Object
DSL: define scenarios
28 29 30 |
# File 'lib/qualspec/suite/dsl.rb', line 28 def scenario(name, &block) @scenarios_list << Scenario.new(name, &block) end |
#temperatures(temps) ⇒ Object
DSL: define temperatures to test across
52 53 54 55 56 57 58 59 60 |
# File 'lib/qualspec/suite/dsl.rb', line 52 def temperatures(temps) temps = Array(temps) temps.each do |t| next if t.nil? raise ArgumentError, "Temperature must be numeric, got #{t.inspect}" unless t.is_a?(Numeric) raise ArgumentError, "Temperature #{t} outside valid range 0.0-2.0" unless (0.0..2.0).cover?(t) end @temperature_list = temps end |
#variants(factory: :prompt_variant, &block) ⇒ Object
DSL: configure variants using FactoryBot
44 45 46 |
# File 'lib/qualspec/suite/dsl.rb', line 44 def variants(factory: :prompt_variant, &block) @variants_config = VariantsConfig.new(factory: factory, &block) end |