Class: Promptmenot::Result
- Inherits:
-
Object
- Object
- Promptmenot::Result
- Defined in:
- lib/promptmenot/result.rb
Instance Attribute Summary collapse
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #categories_detected ⇒ Object
- #high_confidence_matches ⇒ Object
-
#initialize(text:, matches: []) ⇒ Result
constructor
A new instance of Result.
- #patterns_detected ⇒ Object
- #safe? ⇒ Boolean
- #summary ⇒ Object
- #unsafe? ⇒ Boolean
Constructor Details
#initialize(text:, matches: []) ⇒ Result
Returns a new instance of Result.
7 8 9 10 |
# File 'lib/promptmenot/result.rb', line 7 def initialize(text:, matches: []) @text = text @matches = matches.freeze end |
Instance Attribute Details
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
5 6 7 |
# File 'lib/promptmenot/result.rb', line 5 def matches @matches end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
5 6 7 |
# File 'lib/promptmenot/result.rb', line 5 def text @text end |
Instance Method Details
#categories_detected ⇒ Object
20 21 22 |
# File 'lib/promptmenot/result.rb', line 20 def categories_detected matches.map(&:category).uniq end |
#high_confidence_matches ⇒ Object
28 29 30 |
# File 'lib/promptmenot/result.rb', line 28 def high_confidence_matches matches.select { |m| m.confidence == :high } end |
#patterns_detected ⇒ Object
24 25 26 |
# File 'lib/promptmenot/result.rb', line 24 def patterns_detected matches.map(&:pattern_name).uniq end |
#safe? ⇒ Boolean
12 13 14 |
# File 'lib/promptmenot/result.rb', line 12 def safe? matches.empty? end |
#summary ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/promptmenot/result.rb', line 32 def summary return "No prompt injection detected." if safe? count = matches.size cats = categories_detected.map { |c| c.to_s.tr("_", " ") }.join(", ") "Detected #{count} potential prompt injection pattern#{"s" if count > 1} " \ "in categories: #{cats}." end |
#unsafe? ⇒ Boolean
16 17 18 |
# File 'lib/promptmenot/result.rb', line 16 def unsafe? !safe? end |