Class: Datadog::AIGuard::Contrib::RubyLLM::MessageAdapter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ai_guard/contrib/ruby_llm/message_adapter.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

RubyLLM messages paired with their AI Guard representation

Instance Method Summary collapse

Constructor Details

#initialize(messages) ⇒ MessageAdapter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MessageAdapter.



13
14
15
# File 'lib/datadog/ai_guard/contrib/ruby_llm/message_adapter.rb', line 13

def initialize(messages)
  @ruby_llm_messages = messages
end

Instance Method Details

#apply_redactions(redacted_messages) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/datadog/ai_guard/contrib/ruby_llm/message_adapter.rb', line 21

def apply_redactions(redacted_messages)
  ai_guard_messages = to_ai_guard
  return @ruby_llm_messages if redacted_messages == ai_guard_messages

  @ruby_llm_messages.each_with_index.map do |message, index|
    original_message = ai_guard_messages[index]
    redacted_message = redacted_messages[index]
    next message if redacted_message == original_message

    RedactionChangeSet.new(original_message, redacted_message).apply_to(message)
  end
end

#to_ai_guard ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
# File 'lib/datadog/ai_guard/contrib/ruby_llm/message_adapter.rb', line 17

def to_ai_guard
  @ai_guard_messages ||= @ruby_llm_messages.map { |message| build_ai_guard_message(message) }
end