Class: RailsAiBridge::Tools::ProvenanceLines

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/tools/provenance_lines.rb

Overview

Renders confidence tags into tool output when confidence_tags_enabled is on.

With tags off, every method returns its input unchanged, so tool output stays byte-identical to output rendered before tags existed.

Instance Method Summary collapse

Constructor Details

#initialize(enabled) ⇒ ProvenanceLines

Returns a new instance of ProvenanceLines.

Parameters:

  • enabled (Boolean) —

    whether tags are rendered



11
12
13
# File 'lib/rails_ai_bridge/tools/provenance_lines.rb', line 11

def initialize(enabled)
  @enabled = enabled
end

Instance Method Details

Returns verification summary line, or nil when disabled or empty.

Parameters:

  • provenances (Array<Symbol, nil>) —

    provenance of each rendered fact

Returns:

  • (String, nil) —

    verification summary line, or nil when disabled or empty



26
27
28
29
30
# File 'lib/rails_ai_bridge/tools/provenance_lines.rb', line 26

def footer(provenances)
  return unless @enabled

  ConfidenceTag.footer(provenances.map { |source| source || :heuristic }.tally)
end

#tag(text, provenance) ⇒ String

Returns text with a trailing tag when enabled.

Parameters:

  • text (String) —

    fact line without a tag

  • provenance (Symbol, nil) —

    evidence origin of the fact

Returns:

  • (String) —

    text with a trailing tag when enabled



18
19
20
21
22
# File 'lib/rails_ai_bridge/tools/provenance_lines.rb', line 18

def tag(text, provenance)
  return text unless @enabled

  ConfidenceTag.tagged(text, provenance)
end