Class: Qualspec::Suite::Scenario

Inherits:
Object
  • Object
show all
Defined in:
lib/qualspec/suite/scenario.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Scenario

Returns a new instance of Scenario.



8
9
10
11
12
13
14
15
16
17
# File 'lib/qualspec/suite/scenario.rb', line 8

def initialize(name, &block)
  @name = name
  @prompt_text = nil
  @system_prompt = nil
  @evaluations = []
  @rubric_name = nil
  @context = nil

  instance_eval(&block) if block_given? # rubocop:disable Style/EvalWithLocation -- DSL pattern requires eval
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'lib/qualspec/suite/scenario.rb', line 6

def context
  @context
end

#evaluationsObject (readonly)

Returns the value of attribute evaluations.



6
7
8
# File 'lib/qualspec/suite/scenario.rb', line 6

def evaluations
  @evaluations
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/qualspec/suite/scenario.rb', line 6

def name
  @name
end

#prompt_textObject (readonly)

Returns the value of attribute prompt_text.



6
7
8
# File 'lib/qualspec/suite/scenario.rb', line 6

def prompt_text
  @prompt_text
end

#rubric_nameObject (readonly)

Returns the value of attribute rubric_name.



6
7
8
# File 'lib/qualspec/suite/scenario.rb', line 6

def rubric_name
  @rubric_name
end

#system_promptObject (readonly)

Returns the value of attribute system_prompt.



6
7
8
# File 'lib/qualspec/suite/scenario.rb', line 6

def system_prompt
  @system_prompt
end

Instance Method Details

#all_criteriaObject

Get all criteria to evaluate (from explicit evals + rubric)



45
46
47
48
49
50
51
52
53
54
# File 'lib/qualspec/suite/scenario.rb', line 45

def all_criteria
  criteria = @evaluations.dup

  if @rubric_name
    rubric_obj = Rubric.find(@rubric_name)
    criteria.concat(rubric_obj.criteria)
  end

  criteria
end

#compose_prompt(variant = nil) ⇒ String

Compose the final prompt with variant modifications

Parameters:

  • variant (PromptVariant, nil) (defaults to: nil)

    The variant to apply

Returns:

  • (String)

    The composed prompt



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/qualspec/suite/scenario.rb', line 60

def compose_prompt(variant = nil)
  return @prompt_text unless variant

  # If variant has a full_prompt (composed by FactoryBot callback), use it
  if variant.full_prompt && !variant.full_prompt.empty?
    variant.full_prompt
  elsif variant.base_prompt && !variant.base_prompt.empty?
    # Variant provides its own base prompt
    variant.base_prompt
  else
    # Compose: credential prefix + scenario prompt
    parts = []
    parts << variant.credential if variant.credential && !variant.credential.empty?
    parts << @prompt_text
    parts.join(' ')
  end
end

#compose_system_prompt(variant = nil, candidate_system_prompt = nil) ⇒ String?

Compose system prompt with variant and candidate overrides Priority: variant > scenario > candidate

Parameters:

  • variant (PromptVariant, nil) (defaults to: nil)

    The variant

  • candidate_system_prompt (String, nil) (defaults to: nil)

    The candidate’s system prompt

Returns:

  • (String, nil)

    The composed system prompt



84
85
86
# File 'lib/qualspec/suite/scenario.rb', line 84

def compose_system_prompt(variant = nil, candidate_system_prompt = nil)
  variant&.system_prompt || @system_prompt || candidate_system_prompt
end

#criterion(text) ⇒ Object Also known as: evaluate

DSL method to add evaluation criteria



29
30
31
# File 'lib/qualspec/suite/scenario.rb', line 29

def criterion(text)
  @evaluations << text
end

#prompt(text) ⇒ Object

DSL methods



20
21
22
# File 'lib/qualspec/suite/scenario.rb', line 20

def prompt(text)
  @prompt_text = text
end

#rubric(name) ⇒ Object



36
37
38
# File 'lib/qualspec/suite/scenario.rb', line 36

def rubric(name)
  @rubric_name = name
end

#system(text) ⇒ Object



24
25
26
# File 'lib/qualspec/suite/scenario.rb', line 24

def system(text)
  @system_prompt = text
end

#with_context(text) ⇒ Object



40
41
42
# File 'lib/qualspec/suite/scenario.rb', line 40

def with_context(text)
  @context = text
end