Class: Legion::Extensions::Agentic::Defense::Confabulation::Helpers::Claim

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, claim_type:, confidence:, evidence_strength:) ⇒ Claim

Returns a new instance of Claim.



15
16
17
18
19
20
21
22
23
24
# File 'lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb', line 15

def initialize(content:, claim_type:, confidence:, evidence_strength:)
  @id               = SecureRandom.uuid
  @content          = content
  @claim_type       = claim_type
  @confidence       = confidence.clamp(0.0, 1.0)
  @evidence_strength = evidence_strength.clamp(0.0, 1.0)
  @verified         = false
  @confabulated     = false
  @created_at       = Time.now.utc
end

Instance Attribute Details

#claim_typeObject (readonly)

Returns the value of attribute claim_type.



12
13
14
# File 'lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb', line 12

def claim_type
  @claim_type
end

#confabulatedObject (readonly)

Returns the value of attribute confabulated.



12
13
14
# File 'lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb', line 12

def confabulated
  @confabulated
end

#confidenceObject (readonly)

Returns the value of attribute confidence.



12
13
14
# File 'lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb', line 12

def confidence
  @confidence
end

#contentObject (readonly)

Returns the value of attribute content.



12
13
14
# File 'lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb', line 12

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb', line 12

def created_at
  @created_at
end

#evidence_strengthObject (readonly)

Returns the value of attribute evidence_strength.



12
13
14
# File 'lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb', line 12

def evidence_strength
  @evidence_strength
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb', line 12

def id
  @id
end

#verifiedObject (readonly)

Returns the value of attribute verified.



12
13
14
# File 'lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb', line 12

def verified
  @verified
end

Instance Method Details

#confabulation_riskObject



26
27
28
# File 'lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb', line 26

def confabulation_risk
  (confidence - evidence_strength).clamp(0.0, 1.0)
end

#mark_confabulated!Object



35
36
37
38
# File 'lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb', line 35

def mark_confabulated!
  @confabulated = true
  self
end

#risk_labelObject



40
41
42
43
44
45
# File 'lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb', line 40

def risk_label
  Constants::RISK_LABELS.each do |range, label|
    return label if range.cover?(confabulation_risk)
  end
  :extreme
end

#to_hObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb', line 47

def to_h
  {
    id:                 id,
    content:            content,
    claim_type:         claim_type,
    confidence:         confidence.round(10),
    evidence_strength:  evidence_strength.round(10),
    confabulation_risk: confabulation_risk.round(10),
    risk_label:         risk_label,
    verified:           verified,
    confabulated:       confabulated,
    created_at:         created_at.iso8601
  }
end

#verify!Object



30
31
32
33
# File 'lib/legion/extensions/agentic/defense/confabulation/helpers/claim.rb', line 30

def verify!
  @verified = true
  self
end