pangea-sdk 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.ignore +2 -0
- data/README.md +1 -0
- data/lib/pangea/client.rb +51 -0
- data/lib/pangea/errors.rb +113 -0
- data/lib/pangea/internal/transport/base_client.rb +346 -0
- data/lib/pangea/internal/transport/pooled_net_requester.rb +191 -0
- data/lib/pangea/internal/type/array_of.rb +119 -0
- data/lib/pangea/internal/type/base_model.rb +289 -0
- data/lib/pangea/internal/type/boolean.rb +44 -0
- data/lib/pangea/internal/type/converter.rb +228 -0
- data/lib/pangea/internal/type/hash_of.rb +166 -0
- data/lib/pangea/internal/type/request_parameters.rb +38 -0
- data/lib/pangea/internal/type/union.rb +66 -0
- data/lib/pangea/internal/type/unknown.rb +50 -0
- data/lib/pangea/internal/util.rb +429 -0
- data/lib/pangea/internal.rb +12 -0
- data/lib/pangea/models/ai_guard/classification_result.rb +33 -0
- data/lib/pangea/models/ai_guard/hardening_result.rb +27 -0
- data/lib/pangea/models/ai_guard/language_result.rb +20 -0
- data/lib/pangea/models/ai_guard/malicious_entity_result.rb +42 -0
- data/lib/pangea/models/ai_guard/prompt_injection_result.rb +33 -0
- data/lib/pangea/models/ai_guard/redact_entity_result.rb +43 -0
- data/lib/pangea/models/ai_guard/single_entity_result.rb +21 -0
- data/lib/pangea/models/ai_guard/text_guard_message_param.rb +19 -0
- data/lib/pangea/models/ai_guard/text_guard_params.rb +24 -0
- data/lib/pangea/models/ai_guard/text_guard_result.rb +308 -0
- data/lib/pangea/models/ai_guard/topic_result.rb +33 -0
- data/lib/pangea/models/pangea_response.rb +67 -0
- data/lib/pangea/request_options.rb +35 -0
- data/lib/pangea/services/ai_guard.rb +62 -0
- data/lib/pangea/version.rb +5 -0
- data/lib/pangea.rb +45 -0
- data/manifest.yaml +6 -0
- data/rbi/lib/pangea/client.rbi +25 -0
- data/rbi/lib/pangea/internal/internal.rbi +28 -0
- data/rbi/lib/pangea/internal/transport/base_client.rbi +18 -0
- data/rbi/lib/pangea/internal/type/array_of.rbi +66 -0
- data/rbi/lib/pangea/internal/type/base_model.rbi +33 -0
- data/rbi/lib/pangea/internal/type/boolean.rbi +46 -0
- data/rbi/lib/pangea/internal/type/converter.rbi +38 -0
- data/rbi/lib/pangea/internal/type/request_parameters.rbi +20 -0
- data/rbi/lib/pangea/internal/type/union.rbi +21 -0
- data/rbi/lib/pangea/internal/type/unknown.rbi +20 -0
- data/rbi/lib/pangea/internal.rbi +7 -0
- data/rbi/lib/pangea/models/ai_guard/text_guard_message_param.rbi +15 -0
- data/rbi/lib/pangea/models/ai_guard/text_guard_result.rbi +13 -0
- data/rbi/lib/pangea/models/pangea_response.rbi +31 -0
- data/rbi/lib/pangea/request_options.rbi +17 -0
- data/rbi/lib/pangea/services/ai_guard.rbi +28 -0
- data/rbi/lib/pangea/version.rbi +5 -0
- data/sig/pangea/client.rbs +12 -0
- data/sig/pangea/internal/transport/base_client.rbs +14 -0
- data/sig/pangea/internal/type/base_model.rbs +12 -0
- data/sig/pangea/internal/type/boolean.rbs +10 -0
- data/sig/pangea/internal/type/converter.rbs +9 -0
- data/sig/pangea/internal/type/request_parameters.rbs +15 -0
- data/sig/pangea/models/pangea_response.rbs +12 -0
- data/sig/pangea/models/text_guard_result.rbs +19 -0
- data/sig/pangea/request_options.rbs +34 -0
- data/sig/pangea/services/ai_guard.rbs +12 -0
- data/sig/pangea/version.rbs +3 -0
- metadata +126 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pangea
|
4
|
+
module Models
|
5
|
+
module AiGuard
|
6
|
+
class TextGuardParams < Pangea::Internal::Type::BaseModel
|
7
|
+
extend Pangea::Internal::Type::RequestParameters::Converter
|
8
|
+
include Pangea::Internal::Type::RequestParameters
|
9
|
+
|
10
|
+
optional :text, String, nil?: true
|
11
|
+
|
12
|
+
# module Prompt
|
13
|
+
# extend Pangea::Internal::Type::Union
|
14
|
+
|
15
|
+
# variant String
|
16
|
+
|
17
|
+
# variant -> { Pangea::Models::TextGuardParams::Prompt::StringArray }
|
18
|
+
|
19
|
+
# StringArray = Array(String)
|
20
|
+
# end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,308 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pangea
|
4
|
+
module Models
|
5
|
+
module AiGuard
|
6
|
+
class TextGuardResult < Pangea::Internal::Type::BaseModel
|
7
|
+
# @!attribute detectors
|
8
|
+
# Result of the recipe analyzing and input prompt.
|
9
|
+
#
|
10
|
+
# @return [Detectors]
|
11
|
+
required :detectors, -> { Detectors }
|
12
|
+
|
13
|
+
# @!attribute prompt_text
|
14
|
+
# Updated prompt text, if applicable.
|
15
|
+
#
|
16
|
+
# @return [String, nil]
|
17
|
+
optional :prompt_text, String, nil?: true
|
18
|
+
|
19
|
+
# @!attribute prompt_messages
|
20
|
+
# Updated structured prompt, if applicable.
|
21
|
+
#
|
22
|
+
# @return [Pangea::Internal::Type::Unknown, nil]
|
23
|
+
optional :prompt_messages, Hash, nil?: true
|
24
|
+
|
25
|
+
# @!attribute blocked
|
26
|
+
# Whether or not the prompt triggered a block detection.
|
27
|
+
#
|
28
|
+
# @return [Boolean, nil]
|
29
|
+
optional :blocked, Pangea::Internal::Type::Boolean, nil?: true
|
30
|
+
|
31
|
+
# @!attribute recipe
|
32
|
+
# The Recipe that was used.
|
33
|
+
#
|
34
|
+
# @return [String, nil]
|
35
|
+
optional :recipe, String, nil?: true
|
36
|
+
|
37
|
+
# @!attribute fpe_context
|
38
|
+
# If an FPE redaction method returned results, this will be the
|
39
|
+
# context passed to unredact.
|
40
|
+
#
|
41
|
+
# @return [String, nil]
|
42
|
+
optional :fpe_context, String, nil?: true
|
43
|
+
|
44
|
+
class Detectors < Pangea::Internal::Type::BaseModel
|
45
|
+
# @!attribute prompt_injection
|
46
|
+
#
|
47
|
+
# @return [PromptInjectionResult, nil]
|
48
|
+
optional :prompt_injection, -> { PromptInjection }, nil?: true
|
49
|
+
|
50
|
+
# @!attribute gibberish
|
51
|
+
#
|
52
|
+
# @return [Gibberish, nil]
|
53
|
+
optional :gibberish, -> { Gibberish }, nil?: true
|
54
|
+
|
55
|
+
# @!attribute sentiment
|
56
|
+
#
|
57
|
+
# @return [Sentiment, nil]
|
58
|
+
optional :sentiment, -> { Sentiment }, nil?: true
|
59
|
+
|
60
|
+
# @!attribute selfharm
|
61
|
+
#
|
62
|
+
# @return [SelfHarm, nil]
|
63
|
+
optional :selfharm, -> { SelfHarm }, nil?: true
|
64
|
+
|
65
|
+
# @!attribute pii_entity
|
66
|
+
#
|
67
|
+
# @return [PiiEntity, nil]
|
68
|
+
optional :pii_entity, -> { PiiEntity }, nil?: true
|
69
|
+
|
70
|
+
# @!attribute malicious_entity
|
71
|
+
#
|
72
|
+
# @return [MaliciousEntity, nil]
|
73
|
+
optional :malicious_entity, -> { MaliciousEntity }, nil?: true
|
74
|
+
|
75
|
+
# @!attribute custom_entity
|
76
|
+
#
|
77
|
+
# @return [CustomEntity, nil]
|
78
|
+
optional :custom_entity, -> { CustomEntity }, nil?: true
|
79
|
+
|
80
|
+
# @!attribute secrets_detection
|
81
|
+
#
|
82
|
+
# @return [SecretsDetection, nil]
|
83
|
+
optional :secrets_detection, -> { SecretsDetection }, nil?: true
|
84
|
+
|
85
|
+
# @!attribute competitors
|
86
|
+
#
|
87
|
+
# @return [Competitors, nil]
|
88
|
+
optional :competitors, -> { Competitors }, nil?: true
|
89
|
+
|
90
|
+
# @!attribute profanity_and_toxicity
|
91
|
+
#
|
92
|
+
# @return [ProfanityAndToxicity, nil]
|
93
|
+
optional :profanity_and_toxicity, -> { ProfanityAndToxicity }, nil?: true
|
94
|
+
|
95
|
+
# @!attribute hardening
|
96
|
+
#
|
97
|
+
# @return [Hardening, nil]
|
98
|
+
optional :hardening, -> { Hardening }, nil?: true
|
99
|
+
|
100
|
+
# @!attribute language_detection
|
101
|
+
#
|
102
|
+
# @return [LanguageDetection, nil]
|
103
|
+
optional :language_detection, -> { LanguageDetection }, nil?: true
|
104
|
+
|
105
|
+
# @!attribute topic
|
106
|
+
#
|
107
|
+
# @return [Topic, nil]
|
108
|
+
optional :topic, -> { Topic }, nil?: true
|
109
|
+
|
110
|
+
# @!attribute code_detection
|
111
|
+
#
|
112
|
+
# @return [CodeDetection, nil]
|
113
|
+
optional :code_detection, -> { CodeDetection }, nil?: true
|
114
|
+
|
115
|
+
class PromptInjection < Pangea::Internal::Type::BaseModel
|
116
|
+
# @!attribute detected
|
117
|
+
# Whether or not the Malicious Prompt was detected.
|
118
|
+
#
|
119
|
+
# @return [Pangea::Internal::Type::Boolean, nil]
|
120
|
+
optional :detected, Pangea::Internal::Type::Boolean, nil?: true
|
121
|
+
|
122
|
+
# @!attribute data
|
123
|
+
# Details about the analyzers.
|
124
|
+
#
|
125
|
+
# @return [Pangea::Models::AiGuard::PromptInjectionResult, nil]
|
126
|
+
optional :data, Pangea::Models::AiGuard::PromptInjectionResult, nil?: true
|
127
|
+
end
|
128
|
+
|
129
|
+
class Gibberish < Pangea::Internal::Type::BaseModel
|
130
|
+
# @!attribute detected
|
131
|
+
# Whether or not the Gibberish was detected.
|
132
|
+
#
|
133
|
+
# @return [Pangea::Internal::Type::Boolean, nil]
|
134
|
+
optional :detected, Pangea::Internal::Type::Boolean, nil?: true
|
135
|
+
|
136
|
+
# @!attribute data
|
137
|
+
# Details about the analyzers.
|
138
|
+
#
|
139
|
+
# @return [Pangea::Models::AiGuard::ClassificationResult, nil]
|
140
|
+
optional :data, Pangea::Models::AiGuard::ClassificationResult, nil?: true
|
141
|
+
end
|
142
|
+
|
143
|
+
class Sentiment < Pangea::Internal::Type::BaseModel
|
144
|
+
# @!attribute detected
|
145
|
+
# Whether or not the Negative Sentiment was detected.
|
146
|
+
#
|
147
|
+
# @return [Pangea::Internal::Type::Boolean, nil]
|
148
|
+
optional :detected, Pangea::Internal::Type::Boolean, nil?: true
|
149
|
+
|
150
|
+
# @!attribute data
|
151
|
+
# Details about the analyzers.
|
152
|
+
#
|
153
|
+
# @return [Pangea::Models::AiGuard::ClassificationResult, nil]
|
154
|
+
optional :data, Pangea::Models::AiGuard::ClassificationResult, nil?: true
|
155
|
+
end
|
156
|
+
|
157
|
+
class SelfHarm < Pangea::Internal::Type::BaseModel
|
158
|
+
# @!attribute detected
|
159
|
+
# Whether or not the Self-harm was detected.
|
160
|
+
#
|
161
|
+
# @return [Pangea::Internal::Type::Boolean, nil]
|
162
|
+
optional :detected, Pangea::Internal::Type::Boolean, nil?: true
|
163
|
+
|
164
|
+
# @!attribute data
|
165
|
+
# Details about the analyzers.
|
166
|
+
#
|
167
|
+
# @return [Pangea::Models::AiGuard::ClassificationResult, nil]
|
168
|
+
optional :data, Pangea::Models::AiGuard::ClassificationResult, nil?: true
|
169
|
+
end
|
170
|
+
|
171
|
+
class PiiEntity < Pangea::Internal::Type::BaseModel
|
172
|
+
# @!attribute detected
|
173
|
+
# Whether or not the PII Entities was detected.
|
174
|
+
#
|
175
|
+
# @return [Pangea::Internal::Type::Boolean, nil]
|
176
|
+
optional :detected, Pangea::Internal::Type::Boolean, nil?: true
|
177
|
+
|
178
|
+
# @!attribute data
|
179
|
+
# Details about the detected entities
|
180
|
+
#
|
181
|
+
# @return [Pangea::Models::AiGuard::RedactEntityResult, nil]
|
182
|
+
optional :data, Pangea::Models::AiGuard::RedactEntityResult, nil?: true
|
183
|
+
end
|
184
|
+
|
185
|
+
class MaliciousEntity < Pangea::Internal::Type::BaseModel
|
186
|
+
# @!attribute detected
|
187
|
+
# Whether or not the Malicious Entities was detected.
|
188
|
+
#
|
189
|
+
# @return [Pangea::Internal::Type::Boolean, nil]
|
190
|
+
optional :detected, Pangea::Internal::Type::Boolean, nil?: true
|
191
|
+
|
192
|
+
# @!attribute data
|
193
|
+
# Details about the detected entities
|
194
|
+
#
|
195
|
+
# @return [Pangea::Models::AiGuard::MaliciousEntityResult, nil]
|
196
|
+
optional :data, Pangea::Models::AiGuard::MaliciousEntityResult, nil?: true
|
197
|
+
end
|
198
|
+
|
199
|
+
class CustomEntity < Pangea::Internal::Type::BaseModel
|
200
|
+
# @!attribute detected
|
201
|
+
# Whether or not the Custom Entities was detected.
|
202
|
+
#
|
203
|
+
# @return [Pangea::Internal::Type::Boolean, nil]
|
204
|
+
optional :detected, Pangea::Internal::Type::Boolean, nil?: true
|
205
|
+
|
206
|
+
# @!attribute data
|
207
|
+
# Details about the detected entities
|
208
|
+
#
|
209
|
+
# @return [Pangea::Models::AiGuard::RedactEntityResult, nil]
|
210
|
+
optional :data, Pangea::Models::AiGuard::RedactEntityResult, nil?: true
|
211
|
+
end
|
212
|
+
|
213
|
+
class SecretsDetection < Pangea::Internal::Type::BaseModel
|
214
|
+
# @!attribute detected
|
215
|
+
# Whether or not the Secret Entities was detected.
|
216
|
+
#
|
217
|
+
# @return [Pangea::Internal::Type::Boolean, nil]
|
218
|
+
optional :detected, Pangea::Internal::Type::Boolean, nil?: true
|
219
|
+
|
220
|
+
# @!attribute data
|
221
|
+
# Details about the detected entities
|
222
|
+
#
|
223
|
+
# @return [Pangea::Models::AiGuard::RedactEntityResult, nil]
|
224
|
+
optional :data, Pangea::Models::AiGuard::RedactEntityResult, nil?: true
|
225
|
+
end
|
226
|
+
|
227
|
+
class Competitors < Pangea::Internal::Type::BaseModel
|
228
|
+
# @!attribute detected
|
229
|
+
# Whether or not the Competitors was detected.
|
230
|
+
#
|
231
|
+
# @return [Pangea::Internal::Type::Boolean, nil]
|
232
|
+
optional :detected, Pangea::Internal::Type::Boolean, nil?: true
|
233
|
+
|
234
|
+
# @!attribute data
|
235
|
+
# Details about the detected entities
|
236
|
+
#
|
237
|
+
# @return [Pangea::Models::AiGuard::SingleEntityResult, nil]
|
238
|
+
optional :data, Pangea::Models::AiGuard::SingleEntityResult, nil?: true
|
239
|
+
end
|
240
|
+
|
241
|
+
class ProfanityAndToxicity < Pangea::Internal::Type::BaseModel
|
242
|
+
# @!attribute detected
|
243
|
+
# Whether or not the Profanity and Toxic was detected.
|
244
|
+
#
|
245
|
+
# @return [Pangea::Internal::Type::Boolean, nil]
|
246
|
+
optional :detected, Pangea::Internal::Type::Boolean, nil?: true
|
247
|
+
|
248
|
+
# @!attribute data
|
249
|
+
# Details about the detected entities.
|
250
|
+
#
|
251
|
+
# @return [Pangea::Models::AiGuard::ClassificationResult, nil]
|
252
|
+
optional :data, Pangea::Models::AiGuard::ClassificationResult, nil?: true
|
253
|
+
end
|
254
|
+
|
255
|
+
class Hardening < Pangea::Internal::Type::BaseModel
|
256
|
+
# @!attribute data
|
257
|
+
# Details about the detected languages.
|
258
|
+
#
|
259
|
+
# @return [Pangea::Models::AiGuard::HardeningResult, nil]
|
260
|
+
optional :data, Pangea::Models::AiGuard::HardeningResult, nil?: true
|
261
|
+
end
|
262
|
+
|
263
|
+
class LanguageDetection < Pangea::Internal::Type::BaseModel
|
264
|
+
# @!attribute detected
|
265
|
+
# Whether or not the Languages was detected.
|
266
|
+
#
|
267
|
+
# @return [Pangea::Internal::Type::Boolean, nil]
|
268
|
+
optional :detected, Pangea::Internal::Type::Boolean, nil?: true
|
269
|
+
|
270
|
+
# @!attribute data
|
271
|
+
# Details about the detected languages.
|
272
|
+
#
|
273
|
+
# @return [Pangea::Models::AiGuard::LanguageResult, nil]
|
274
|
+
optional :data, Pangea::Models::AiGuard::LanguageResult, nil?: true
|
275
|
+
end
|
276
|
+
|
277
|
+
class Topic < Pangea::Internal::Type::BaseModel
|
278
|
+
# @!attribute detected
|
279
|
+
# Whether or not the Topics was detected.
|
280
|
+
#
|
281
|
+
# @return [Pangea::Internal::Type::Boolean, nil]
|
282
|
+
optional :detected, Pangea::Internal::Type::Boolean, nil?: true
|
283
|
+
|
284
|
+
# @!attribute data
|
285
|
+
# Details about the detected topics.
|
286
|
+
#
|
287
|
+
# @return [Pangea::Models::AiGuard::TopicResult, nil]
|
288
|
+
optional :data, Pangea::Models::AiGuard::TopicResult, nil?: true
|
289
|
+
end
|
290
|
+
|
291
|
+
class CodeDetection < Pangea::Internal::Type::BaseModel
|
292
|
+
# @!attribute detected
|
293
|
+
# Whether or not the Code was detected.
|
294
|
+
#
|
295
|
+
# @return [Pangea::Internal::Type::Boolean, nil]
|
296
|
+
optional :detected, Pangea::Internal::Type::Boolean, nil?: true
|
297
|
+
|
298
|
+
# @!attribute data
|
299
|
+
# Details about the detected code.
|
300
|
+
#
|
301
|
+
# @return [Pangea::Models::AiGuard::LanguageResult, nil]
|
302
|
+
optional :data, Pangea::Models::AiGuard::LanguageResult, nil?: true
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pangea
|
4
|
+
module Models
|
5
|
+
module AiGuard
|
6
|
+
class TopicResult < Pangea::Internal::Type::BaseModel
|
7
|
+
# @!attribute action
|
8
|
+
# The action taken by this Detector
|
9
|
+
#
|
10
|
+
# @return [String, nil]
|
11
|
+
optional :action, String, nil?: true
|
12
|
+
|
13
|
+
# @!attribute topics
|
14
|
+
# List of topics detected
|
15
|
+
#
|
16
|
+
# @return [Pangea::Internal::Type::ArrayOf<Topic>, nil]
|
17
|
+
optional :topics, Pangea::Internal::Type::ArrayOf[-> { Topic }], nil?: true
|
18
|
+
|
19
|
+
class Topic < Pangea::Internal::Type::BaseModel
|
20
|
+
# @!attribute topic
|
21
|
+
#
|
22
|
+
# @return [String]
|
23
|
+
required :topic, String
|
24
|
+
|
25
|
+
# @!attribute confidence
|
26
|
+
#
|
27
|
+
# @return [Float]
|
28
|
+
required :confidence, Float
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pangea
|
4
|
+
module Models
|
5
|
+
# @generic Result
|
6
|
+
class PangeaResponse
|
7
|
+
# A unique identifier assigned to each request made to the API. It is used
|
8
|
+
# to track and identify a specific request and its associated data. The
|
9
|
+
# `request_id` can be helpful for troubleshooting, auditing, and tracing
|
10
|
+
# the flow of requests within the system. It allows users to reference and
|
11
|
+
# retrieve information related to a particular request, such as the
|
12
|
+
# response, parameters, and raw data associated with that specific
|
13
|
+
# request.
|
14
|
+
#
|
15
|
+
# @return [String]
|
16
|
+
attr_accessor :request_id
|
17
|
+
|
18
|
+
# The timestamp indicates the exact moment when a request is made to the
|
19
|
+
# API. It represents the date and time at which the request was initiated
|
20
|
+
# by the client. The `request_time` is useful for tracking and analyzing
|
21
|
+
# the timing of requests, measuring response times, and monitoring
|
22
|
+
# performance metrics. It allows users to determine the duration between
|
23
|
+
# the request initiation and the corresponding response, aiding in the
|
24
|
+
# assessment of API performance and latency.
|
25
|
+
#
|
26
|
+
# @return [String]
|
27
|
+
attr_accessor :request_time
|
28
|
+
|
29
|
+
# Duration it takes for the API to process a request and generate a
|
30
|
+
# response. It represents the elapsed time from when the request is
|
31
|
+
# received by the API to when the corresponding response is returned to
|
32
|
+
# the client.
|
33
|
+
#
|
34
|
+
# @return [String]
|
35
|
+
attr_accessor :response_time
|
36
|
+
|
37
|
+
# It represents the status or outcome of the API request made for IP
|
38
|
+
# information. It indicates the current state or condition of the request
|
39
|
+
# and provides information on the success or failure of the request.
|
40
|
+
#
|
41
|
+
# @return [String]
|
42
|
+
attr_accessor :status
|
43
|
+
|
44
|
+
# Provides a concise and brief overview of the purpose or primary
|
45
|
+
# objective of the API endpoint. It serves as a high-level summary or
|
46
|
+
# description of the functionality or feature offered by the endpoint.
|
47
|
+
#
|
48
|
+
# @return [String]
|
49
|
+
attr_accessor :summary
|
50
|
+
|
51
|
+
# @return [generic<Result> | nil]
|
52
|
+
attr_accessor :result
|
53
|
+
|
54
|
+
# @api private
|
55
|
+
#
|
56
|
+
# @param response_data [Hash{Symbol=>Object}]
|
57
|
+
def initialize(response_data:, model:)
|
58
|
+
@request_id = response_data[:request_id]
|
59
|
+
@request_time = response_data[:request_time]
|
60
|
+
@response_time = response_data[:response_time]
|
61
|
+
@status = response_data[:status]
|
62
|
+
@summary = response_data[:summary]
|
63
|
+
@result = Pangea::Internal::Type::Converter.coerce(model, response_data[:result])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pangea
|
4
|
+
class RequestOptions < Pangea::Internal::Type::BaseModel
|
5
|
+
# @api private
|
6
|
+
#
|
7
|
+
# @param opts [Pangea::RequestOptions, Hash{Symbol=>Object}]
|
8
|
+
#
|
9
|
+
# @raise [ArgumentError]
|
10
|
+
def self.validate!(opts)
|
11
|
+
case opts
|
12
|
+
in Pangea::RequestOptions | Hash
|
13
|
+
opts.to_h.each_key do |k|
|
14
|
+
unless fields.include?(k)
|
15
|
+
raise ArgumentError.new("Request `opts` keys must be one of #{fields.keys}, got #{k.inspect}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
else
|
19
|
+
raise ArgumentError.new("Request `opts` must be a Hash or RequestOptions, got #{opts.inspect}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @!attribute max_retries
|
24
|
+
# Maximum number of retries to attempt after a failed initial request.
|
25
|
+
#
|
26
|
+
# @return [Integer, nil]
|
27
|
+
optional :max_retries, Integer
|
28
|
+
|
29
|
+
# @!attribute timeout
|
30
|
+
# Request timeout in seconds.
|
31
|
+
#
|
32
|
+
# @return [Float, nil]
|
33
|
+
optional :timeout, Float
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pangea
|
4
|
+
module Services
|
5
|
+
class AiGuard
|
6
|
+
# Creates and returns a new client for interacting with the
|
7
|
+
# Pangea AI Guard API.
|
8
|
+
#
|
9
|
+
# @param api_token [String, nil]
|
10
|
+
# @param base_url [String, nil]
|
11
|
+
# @param domain [String, nil]
|
12
|
+
def initialize(
|
13
|
+
api_token: nil,
|
14
|
+
base_url: nil,
|
15
|
+
domain: nil
|
16
|
+
)
|
17
|
+
if !base_url && domain
|
18
|
+
base_url = "https://ai-guard.#{domain}"
|
19
|
+
end
|
20
|
+
|
21
|
+
base_url ||= "https://ai-guard.aws.us.pangea.cloud"
|
22
|
+
|
23
|
+
@client = Pangea::Client.new(api_token: api_token, base_url: base_url)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Analyze and redact text to avoid manipulation of the model, addition of
|
27
|
+
# malicious content, and other undesirable data transfers.
|
28
|
+
#
|
29
|
+
# @overload guard_text(text:, recipe:, debug:, request_options: {})
|
30
|
+
# @overload guard_text(messages:, recipe:, debug:, request_options: {})
|
31
|
+
#
|
32
|
+
# @param text [String, nil] Text to be scanned by AI Guard for PII,
|
33
|
+
# sensitive data, malicious content, and other data types defined by the
|
34
|
+
# configuration. Supports processing up to 20 KiB of text.
|
35
|
+
# @param messages [Array<Pangea::Models::AiGuard::TextGuardMessageParam>, nil]
|
36
|
+
# Structured messages data to be scanned by AI Guard for PII, sensitive
|
37
|
+
# data, malicious content, and other data types defined by the
|
38
|
+
# configuration. Supports processing up to 20 KiB of JSON text using
|
39
|
+
# Pangea message format.
|
40
|
+
# @param recipe [String, nil] Recipe key of a configuration of data types
|
41
|
+
# and settings defined in the Pangea User Console. It specifies the
|
42
|
+
# rules that are to be applied to the text, such as defang malicious
|
43
|
+
# URLs.
|
44
|
+
# @param debug [Boolean, nil] Setting this value to true will provide a
|
45
|
+
# detailed analysis of the text data.
|
46
|
+
# @param request_options [Pangea::RequestOptions, Hash{Symbol=>Object}, nil]
|
47
|
+
#
|
48
|
+
# @return [Pangea::Models::PangeaResponse<Pangea::Models::AiGuard::TextGuardResult>]
|
49
|
+
def guard_text(params)
|
50
|
+
parsed, options = Pangea::Models::AiGuard::TextGuardParams.dump_request(params)
|
51
|
+
@client.request(
|
52
|
+
method: :post,
|
53
|
+
path: "v1/text/guard",
|
54
|
+
body: parsed,
|
55
|
+
structure: Pangea::Models::PangeaResponse,
|
56
|
+
model: Pangea::Models::AiGuard::TextGuardResult,
|
57
|
+
options: options
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/pangea.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cgi"
|
4
|
+
require "date"
|
5
|
+
require "json"
|
6
|
+
require "net/http"
|
7
|
+
require "time"
|
8
|
+
|
9
|
+
require "connection_pool"
|
10
|
+
|
11
|
+
require_relative "pangea/errors"
|
12
|
+
require_relative "pangea/version"
|
13
|
+
|
14
|
+
require_relative "pangea/internal/util"
|
15
|
+
|
16
|
+
require_relative "pangea/internal/transport/pooled_net_requester"
|
17
|
+
require_relative "pangea/internal/transport/base_client"
|
18
|
+
|
19
|
+
require_relative "pangea/internal/type/converter"
|
20
|
+
require_relative "pangea/internal/type/array_of"
|
21
|
+
require_relative "pangea/internal/type/hash_of"
|
22
|
+
require_relative "pangea/internal/type/base_model"
|
23
|
+
require_relative "pangea/internal/type/boolean"
|
24
|
+
require_relative "pangea/internal/type/request_parameters"
|
25
|
+
require_relative "pangea/internal/type/union"
|
26
|
+
require_relative "pangea/internal/type/unknown"
|
27
|
+
|
28
|
+
require_relative "pangea/internal"
|
29
|
+
require_relative "pangea/client"
|
30
|
+
require_relative "pangea/request_options"
|
31
|
+
|
32
|
+
require_relative "pangea/models/pangea_response"
|
33
|
+
require_relative "pangea/models/ai_guard/classification_result"
|
34
|
+
require_relative "pangea/models/ai_guard/hardening_result"
|
35
|
+
require_relative "pangea/models/ai_guard/language_result"
|
36
|
+
require_relative "pangea/models/ai_guard/malicious_entity_result"
|
37
|
+
require_relative "pangea/models/ai_guard/prompt_injection_result"
|
38
|
+
require_relative "pangea/models/ai_guard/redact_entity_result"
|
39
|
+
require_relative "pangea/models/ai_guard/single_entity_result"
|
40
|
+
require_relative "pangea/models/ai_guard/topic_result"
|
41
|
+
require_relative "pangea/models/ai_guard/text_guard_message_param"
|
42
|
+
require_relative "pangea/models/ai_guard/text_guard_params"
|
43
|
+
require_relative "pangea/models/ai_guard/text_guard_result"
|
44
|
+
|
45
|
+
require_relative "pangea/services/ai_guard"
|
data/manifest.yaml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# typed: strong
|
2
|
+
|
3
|
+
module Pangea
|
4
|
+
class Client < Pangea::Internal::Transport::BaseClient
|
5
|
+
sig { returns(String) }
|
6
|
+
attr_reader :api_token
|
7
|
+
|
8
|
+
# @api private
|
9
|
+
sig { override.returns(T::Hash[String, String]) }
|
10
|
+
private def auth_headers; end
|
11
|
+
|
12
|
+
# Creates and returns a new client for interacting with the Pangea API.
|
13
|
+
sig do
|
14
|
+
params(
|
15
|
+
api_token: T.nilable(String),
|
16
|
+
base_url: T.nilable(String)
|
17
|
+
)
|
18
|
+
.returns(T.attached_class)
|
19
|
+
end
|
20
|
+
def self.new(
|
21
|
+
api_token: nil,
|
22
|
+
base_url: nil
|
23
|
+
); end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# typed: strong
|
2
|
+
|
3
|
+
module Pangea
|
4
|
+
module Internal
|
5
|
+
# @api private
|
6
|
+
module Util
|
7
|
+
class << self
|
8
|
+
# @api private
|
9
|
+
sig do
|
10
|
+
params(input: T.anything).returns(
|
11
|
+
T.any(T::Hash[T.anything, T.anything], T.anything)
|
12
|
+
)
|
13
|
+
end
|
14
|
+
def coerce_hash(input)
|
15
|
+
end
|
16
|
+
|
17
|
+
# @api private
|
18
|
+
sig do
|
19
|
+
params(input: T.anything).returns(
|
20
|
+
T.nilable(T::Hash[T.anything, T.anything])
|
21
|
+
)
|
22
|
+
end
|
23
|
+
def coerce_hash!(input)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# typed: strong
|
2
|
+
|
3
|
+
module Pangea
|
4
|
+
module Internal
|
5
|
+
module Transport
|
6
|
+
# @api private
|
7
|
+
class BaseClient
|
8
|
+
abstract!
|
9
|
+
|
10
|
+
PLATFORM_HEADERS = T::Hash[String, String]
|
11
|
+
|
12
|
+
# @api private
|
13
|
+
sig { overridable.returns(T::Hash[String, String]) }
|
14
|
+
private def auth_headers; end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|