Class: Pangea::Services::AiGuard

Inherits:
Object
  • Object
show all
Defined in:
lib/pangea/services/ai_guard.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_token: nil, base_url: nil, domain: nil) ⇒ AiGuard

Creates and returns a new client for interacting with the Pangea AI Guard API.

Parameters:

  • api_token (String, nil) (defaults to: nil)
  • base_url (String, nil) (defaults to: nil)
  • domain (String, nil) (defaults to: nil)


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pangea/services/ai_guard.rb', line 12

def initialize(
  api_token: nil,
  base_url: nil,
  domain: nil
)
  if !base_url && domain
    base_url = "https://ai-guard.#{domain}"
  end

  base_url ||= "https://ai-guard.aws.us.pangea.cloud"

  @client = Pangea::Client.new(api_token: api_token, base_url: base_url)
end

Instance Method Details

#guard_text(text: , recipe: , debug: , request_options: {}) ⇒ Pangea::Models::PangeaResponse<Pangea::Models::AiGuard::TextGuardResult> #guard_text(messages: , recipe: , debug: , request_options: {}) ⇒ Pangea::Models::PangeaResponse<Pangea::Models::AiGuard::TextGuardResult>

Analyze and redact text to avoid manipulation of the model, addition of malicious content, and other undesirable data transfers.

Parameters:

  • text (String, nil) —

    Text to be scanned by AI Guard for PII, sensitive data, malicious content, and other data types defined by the configuration. Supports processing up to 20 KiB of text.

  • messages (Array<Pangea::Models::AiGuard::TextGuardMessageParam>, nil) —

    Structured messages data to be scanned by AI Guard for PII, sensitive data, malicious content, and other data types defined by the configuration. Supports processing up to 20 KiB of JSON text using Pangea message format.

  • recipe (String, nil) —

    Recipe key of a configuration of data types and settings defined in the Pangea User Console. It specifies the rules that are to be applied to the text, such as defang malicious URLs.

  • debug (Boolean, nil) —

    Setting this value to true will provide a detailed analysis of the text data.

  • request_options (Pangea::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/pangea/services/ai_guard.rb', line 49

def guard_text(params)
  parsed, options = Pangea::Models::AiGuard::TextGuardParams.dump_request(params)
  @client.request(
    method: :post,
    path: "v1/text/guard",
    body: parsed,
    structure: Pangea::Models::PangeaResponse,
    model: Pangea::Models::AiGuard::TextGuardResult,
    options: options
  )
end