Class: RubyLLM::TopSecret::Payload
- Inherits:
-
Object
- Object
- RubyLLM::TopSecret::Payload
- Defined in:
- lib/ruby_llm/top_secret/payload.rb
Overview
Instance Method Summary collapse
-
#filter ⇒ void
Filters sensitive content from messages in place using TopSecret::Text.filter_all for consistent labels across turns.
-
#initialize(messages) ⇒ Payload
constructor
A new instance of Payload.
-
#restore(content) ⇒ String, Hash
Restores filtered placeholders in the response content with original values.
Constructor Details
#initialize(messages) ⇒ Payload
Returns a new instance of Payload.
17 18 19 20 |
# File 'lib/ruby_llm/top_secret/payload.rb', line 17 def initialize() @messages = @mapping = {} end |
Instance Method Details
#filter ⇒ void
This method returns an undefined value.
Filters sensitive content from messages in place using TopSecret::Text.filter_all for consistent labels across turns.
25 26 27 28 29 30 31 32 |
# File 'lib/ruby_llm/top_secret/payload.rb', line 25 def filter filterable = @messages.reject { |msg| msg.content.nil? || msg.content.empty? } contents = filterable.map(&:content) batch_result = ::TopSecret::Text.filter_all(contents) filterable.zip(batch_result.items).each { |msg, item| msg.content = item.output } @mapping = batch_result.mapping end |
#restore(content) ⇒ String, Hash
Restores filtered placeholders in the response content with original values. Handles both String and Hash (structured output) content.
39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby_llm/top_secret/payload.rb', line 39 def restore(content) if content.is_a?(Hash) json = JSON.generate(content) restored = ::TopSecret::FilteredText.restore(json, mapping: @mapping) JSON.parse(restored.output) else ::TopSecret::FilteredText.restore(content, mapping: @mapping).output end end |