Class: PromptCanary::RollbackRule

Inherits:
Object
  • Object
show all
Defined in:
lib/prompt_canary/rollback_rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metric:, threshold:, comparator:, window:) ⇒ RollbackRule

Returns a new instance of RollbackRule.



7
8
9
10
11
12
13
# File 'lib/prompt_canary/rollback_rule.rb', line 7

def initialize(metric:, threshold:, comparator:, window:)
  @metric     = metric
  @threshold  = threshold
  @comparator = comparator
  @window     = window
  freeze
end

Instance Attribute Details

#comparatorObject (readonly)

Returns the value of attribute comparator.



5
6
7
# File 'lib/prompt_canary/rollback_rule.rb', line 5

def comparator
  @comparator
end

#metricObject (readonly)

Returns the value of attribute metric.



5
6
7
# File 'lib/prompt_canary/rollback_rule.rb', line 5

def metric
  @metric
end

#thresholdObject (readonly)

Returns the value of attribute threshold.



5
6
7
# File 'lib/prompt_canary/rollback_rule.rb', line 5

def threshold
  @threshold
end

#windowObject (readonly)

Returns the value of attribute window.



5
6
7
# File 'lib/prompt_canary/rollback_rule.rb', line 5

def window
  @window
end

Instance Method Details

#violated_by?(value) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'lib/prompt_canary/rollback_rule.rb', line 15

def violated_by?(value)
  case comparator
  when :greater_than then value > threshold
  when :less_than    then value < threshold
  end
end