Class: Datadog::AIGuard::Evaluation::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ai_guard/evaluation/request.rb

Overview

Request builds the request body from an array of messages and processes the response

Constant Summary collapse

REQUEST_PATH =
"/evaluate"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(messages) ⇒ Request

Returns a new instance of Request.



12
13
14
# File 'lib/datadog/ai_guard/evaluation/request.rb', line 12

def initialize(messages)
  @serialized_messages = serialize_messages(messages)
end

Instance Attribute Details

#serialized_messagesObject (readonly)

Returns the value of attribute serialized_messages.



10
11
12
# File 'lib/datadog/ai_guard/evaluation/request.rb', line 10

def serialized_messages
  @serialized_messages
end

Instance Method Details

#performObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/datadog/ai_guard/evaluation/request.rb', line 16

def perform
  api_client = AIGuard.api_client

  # This should never happen, as we are only calling this method when AI Guard is enabled,
  # and this means the API Client was not initialized properly.
  #
  # Please report this at https://github.com/datadog/dd-trace-rb/blob/master/CONTRIBUTING.md#found-a-bug
  raise "AI Guard API Client not initialized" unless api_client

  raw_response = api_client.post(REQUEST_PATH, body: build_request_body)

  Result.new(raw_response)
end