enkryptai-sdk 1.0.25__py3-none-any.whl → 1.0.27__py3-none-any.whl
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.
- enkryptai_sdk/dto/__init__.py +1 -0
- enkryptai_sdk/dto/datasets.py +66 -16
- enkryptai_sdk/dto/guardrails.py +76 -0
- enkryptai_sdk/dto/models.py +48 -23
- enkryptai_sdk/dto/red_team.py +178 -120
- enkryptai_sdk/guardrails.py +79 -5
- enkryptai_sdk/red_team.py +80 -84
- {enkryptai_sdk-1.0.25.dist-info → enkryptai_sdk-1.0.27.dist-info}/METADATA +1 -1
- {enkryptai_sdk-1.0.25.dist-info → enkryptai_sdk-1.0.27.dist-info}/RECORD +12 -12
- {enkryptai_sdk-1.0.25.dist-info → enkryptai_sdk-1.0.27.dist-info}/WHEEL +1 -1
- {enkryptai_sdk-1.0.25.dist-info → enkryptai_sdk-1.0.27.dist-info}/licenses/LICENSE +0 -0
- {enkryptai_sdk-1.0.25.dist-info → enkryptai_sdk-1.0.27.dist-info}/top_level.txt +0 -0
enkryptai_sdk/guardrails.py
CHANGED
|
@@ -31,7 +31,8 @@ from .dto import (
|
|
|
31
31
|
GuardrailsListPoliciesResponse,
|
|
32
32
|
GuardrailsPolicyAtomizerRequest,
|
|
33
33
|
GuardrailsPolicyAtomizerResponse,
|
|
34
|
-
GuardrailsScanUrlResponse
|
|
34
|
+
GuardrailsScanUrlResponse,
|
|
35
|
+
GuardrailsScanPdfResponse
|
|
35
36
|
)
|
|
36
37
|
|
|
37
38
|
# ---------------------------------------
|
|
@@ -292,16 +293,20 @@ class GuardrailsClient(BaseClient):
|
|
|
292
293
|
|
|
293
294
|
def scan_url(self, url, config=None):
|
|
294
295
|
"""
|
|
295
|
-
Scan a URL for security threats
|
|
296
|
+
Scan a URL for security threats using any combination of available detectors.
|
|
297
|
+
|
|
298
|
+
Supports all detectors available in the detect endpoint, including:
|
|
299
|
+
injection_attack, policy_violation, toxicity, nsfw, pii, bias,
|
|
300
|
+
keyword_detector, copyright_ip, system_prompt, sponge_attack, topic_detector.
|
|
296
301
|
|
|
297
302
|
Parameters:
|
|
298
303
|
- url (str): The URL to scan and analyze.
|
|
299
304
|
- config (dict or GuardrailsConfig, optional): A configuration for detectors.
|
|
300
|
-
|
|
301
|
-
|
|
305
|
+
If a GuardrailsConfig instance is provided, its underlying dictionary will be used.
|
|
306
|
+
If not provided, defaults to injection attack and policy violation detection.
|
|
302
307
|
|
|
303
308
|
Returns:
|
|
304
|
-
- Response from the API.
|
|
309
|
+
- GuardrailsScanUrlResponse: Response from the API containing scan results.
|
|
305
310
|
"""
|
|
306
311
|
# Use default config if none provided
|
|
307
312
|
if config is None:
|
|
@@ -358,6 +363,75 @@ class GuardrailsClient(BaseClient):
|
|
|
358
363
|
except Exception as e:
|
|
359
364
|
raise GuardrailsClientError(str(e))
|
|
360
365
|
|
|
366
|
+
def scan_pdf(self, file, config=None):
|
|
367
|
+
"""
|
|
368
|
+
Scan a PDF for security threats using any combination of available detectors.
|
|
369
|
+
|
|
370
|
+
Supports all detectors available in the detect endpoint, including:
|
|
371
|
+
injection_attack, policy_violation, toxicity, nsfw, pii, bias,
|
|
372
|
+
keyword_detector, copyright_ip, system_prompt, sponge_attack, topic_detector.
|
|
373
|
+
|
|
374
|
+
Parameters:
|
|
375
|
+
- file (str): Base64-encoded PDF string.
|
|
376
|
+
- config (dict or GuardrailsConfig, optional): A configuration for detectors.
|
|
377
|
+
If a GuardrailsConfig instance is provided, its underlying dictionary will be used.
|
|
378
|
+
If not provided, defaults to injection attack and policy violation detection.
|
|
379
|
+
|
|
380
|
+
Returns:
|
|
381
|
+
- GuardrailsScanPdfResponse: Response from the API containing scan results.
|
|
382
|
+
"""
|
|
383
|
+
if config is None:
|
|
384
|
+
config = {
|
|
385
|
+
"injection_attack": {
|
|
386
|
+
"enabled": True
|
|
387
|
+
},
|
|
388
|
+
"policy_violation": {
|
|
389
|
+
"enabled": True,
|
|
390
|
+
"policy_text": "Detect any malicious text or injection attacks",
|
|
391
|
+
"need_explanation": True
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if hasattr(config, "as_dict"):
|
|
396
|
+
config = config.as_dict()
|
|
397
|
+
if hasattr(config, "to_dict"):
|
|
398
|
+
config = config.to_dict()
|
|
399
|
+
|
|
400
|
+
payload = {
|
|
401
|
+
"file": file,
|
|
402
|
+
"detectors": config
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
try:
|
|
406
|
+
response = self._request("POST", "/guardrails/scan-pdf", json=payload)
|
|
407
|
+
if response.get("error"):
|
|
408
|
+
raise GuardrailsClientError(f"API Error: {str(response)}")
|
|
409
|
+
return GuardrailsScanPdfResponse.from_dict(response)
|
|
410
|
+
except Exception as e:
|
|
411
|
+
raise GuardrailsClientError(str(e))
|
|
412
|
+
|
|
413
|
+
def policy_scan_pdf(self, policy_name, file):
|
|
414
|
+
"""
|
|
415
|
+
Apply a specific policy to scan a PDF for security threats.
|
|
416
|
+
|
|
417
|
+
Parameters:
|
|
418
|
+
- policy_name (str): Name of the policy to apply.
|
|
419
|
+
- file (str): Base64-encoded PDF string.
|
|
420
|
+
|
|
421
|
+
Returns:
|
|
422
|
+
- GuardrailsScanPdfResponse: Response from the API containing scan results.
|
|
423
|
+
"""
|
|
424
|
+
headers = {"X-Enkrypt-Policy": policy_name}
|
|
425
|
+
payload = {"file": file}
|
|
426
|
+
|
|
427
|
+
try:
|
|
428
|
+
response = self._request("POST", "/guardrails/policy/scan-pdf", headers=headers, json=payload)
|
|
429
|
+
if response.get("error"):
|
|
430
|
+
raise GuardrailsClientError(f"API Error: {str(response)}")
|
|
431
|
+
return GuardrailsScanPdfResponse.from_dict(response)
|
|
432
|
+
except Exception as e:
|
|
433
|
+
raise GuardrailsClientError(str(e))
|
|
434
|
+
|
|
361
435
|
# ----------------------------
|
|
362
436
|
# Guardrails Policy Endpoints
|
|
363
437
|
# ----------------------------
|
enkryptai_sdk/red_team.py
CHANGED
|
@@ -25,7 +25,7 @@ from .dto import (
|
|
|
25
25
|
RedTeamRiskMitigationSystemPromptConfig,
|
|
26
26
|
RedTeamRiskMitigationSystemPromptResponse,
|
|
27
27
|
RedTeamFindingsResponse,
|
|
28
|
-
RedTeamDownloadLinkResponse
|
|
28
|
+
RedTeamDownloadLinkResponse,
|
|
29
29
|
)
|
|
30
30
|
|
|
31
31
|
|
|
@@ -74,14 +74,16 @@ class RedTeamClient(BaseClient):
|
|
|
74
74
|
config = RedTeamModelHealthConfig.from_dict(config)
|
|
75
75
|
# Print the config as json string
|
|
76
76
|
# print(f"Config: {json.dumps(config.to_dict(), indent=4)}")
|
|
77
|
-
response = self._request(
|
|
77
|
+
response = self._request(
|
|
78
|
+
"POST", "/redteam/model-health", json=config.to_dict()
|
|
79
|
+
)
|
|
78
80
|
# if response.get("error"):
|
|
79
81
|
if response.get("error") not in [None, ""]:
|
|
80
82
|
raise RedTeamClientError(f"API Error: {str(response)}")
|
|
81
83
|
return RedteamModelHealthResponse.from_dict(response)
|
|
82
84
|
except Exception as e:
|
|
83
85
|
raise RedTeamClientError(str(e))
|
|
84
|
-
|
|
86
|
+
|
|
85
87
|
def check_saved_model_health(self, model_saved_name: str, model_version: str):
|
|
86
88
|
"""
|
|
87
89
|
Get the health status of a saved model.
|
|
@@ -91,41 +93,41 @@ class RedTeamClient(BaseClient):
|
|
|
91
93
|
"X-Enkrypt-Model": model_saved_name,
|
|
92
94
|
"X-Enkrypt-Model-Version": model_version,
|
|
93
95
|
}
|
|
94
|
-
response = self._request(
|
|
96
|
+
response = self._request(
|
|
97
|
+
"POST", "/redteam/model/model-health", headers=headers
|
|
98
|
+
)
|
|
95
99
|
# if response.get("error"):
|
|
96
100
|
if response.get("error") not in [None, ""]:
|
|
97
101
|
raise RedTeamClientError(f"API Error: {str(response)}")
|
|
98
102
|
return RedteamModelHealthResponse.from_dict(response)
|
|
99
103
|
except Exception as e:
|
|
100
104
|
raise RedTeamClientError(str(e))
|
|
101
|
-
|
|
105
|
+
|
|
102
106
|
def check_model_health_v3(self, config: RedTeamModelHealthConfigV3):
|
|
103
107
|
"""
|
|
104
108
|
Get the health status of a model using V3 format with endpoint_configuration.
|
|
105
|
-
|
|
109
|
+
|
|
106
110
|
This method accepts endpoint_configuration (similar to add_custom_task) and
|
|
107
111
|
converts it internally to target_model_configuration format for backend compatibility.
|
|
108
|
-
|
|
112
|
+
|
|
109
113
|
Args:
|
|
110
114
|
config (RedTeamModelHealthConfigV3): Configuration object containing endpoint_configuration
|
|
111
|
-
|
|
115
|
+
|
|
112
116
|
Returns:
|
|
113
117
|
RedteamModelHealthResponse: Response from the API containing health status
|
|
114
|
-
|
|
118
|
+
|
|
115
119
|
Raises:
|
|
116
120
|
RedTeamClientError: If there's an error from the API
|
|
117
121
|
"""
|
|
118
122
|
try:
|
|
119
123
|
config = RedTeamModelHealthConfigV3.from_dict(config)
|
|
120
|
-
|
|
124
|
+
|
|
121
125
|
# Convert endpoint_configuration to target_model_configuration
|
|
122
126
|
target_config = config.to_target_model_configuration()
|
|
123
|
-
|
|
127
|
+
|
|
124
128
|
# Create the payload in the format expected by the backend
|
|
125
|
-
payload = {
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
+
payload = {"target_model_configuration": target_config.to_dict()}
|
|
130
|
+
|
|
129
131
|
response = self._request("POST", "/redteam/model-health", json=payload)
|
|
130
132
|
if response.get("error") not in [None, ""]:
|
|
131
133
|
raise RedTeamClientError(f"API Error: {str(response)}")
|
|
@@ -166,9 +168,7 @@ class RedTeamClient(BaseClient):
|
|
|
166
168
|
raise RedTeamClientError(f"API Error: {str(response)}")
|
|
167
169
|
return RedTeamResponse.from_dict(response)
|
|
168
170
|
else:
|
|
169
|
-
raise RedTeamClientError(
|
|
170
|
-
"Please provide a target model configuration"
|
|
171
|
-
)
|
|
171
|
+
raise RedTeamClientError("Please provide a target model configuration")
|
|
172
172
|
|
|
173
173
|
def add_task_with_saved_model(
|
|
174
174
|
self,
|
|
@@ -181,7 +181,7 @@ class RedTeamClient(BaseClient):
|
|
|
181
181
|
"""
|
|
182
182
|
if not model_saved_name:
|
|
183
183
|
raise RedTeamClientError("Please provide a model_saved_name")
|
|
184
|
-
|
|
184
|
+
|
|
185
185
|
if not model_version:
|
|
186
186
|
raise RedTeamClientError("Please provide a model_version. Default is 'v1'")
|
|
187
187
|
|
|
@@ -244,15 +244,13 @@ class RedTeamClient(BaseClient):
|
|
|
244
244
|
|
|
245
245
|
if config.dataset_configuration:
|
|
246
246
|
payload["dataset_configuration"] = DatasetClient.prepare_dataset_payload(
|
|
247
|
-
config.dataset_configuration, True
|
|
248
|
-
else:
|
|
249
|
-
raise RedTeamClientError(
|
|
250
|
-
"Please provide a dataset configuration"
|
|
247
|
+
config.dataset_configuration, True
|
|
251
248
|
)
|
|
252
249
|
|
|
253
250
|
if config.endpoint_configuration:
|
|
254
251
|
payload["endpoint_configuration"] = ModelClient.prepare_model_payload(
|
|
255
|
-
config.endpoint_configuration, True
|
|
252
|
+
config.endpoint_configuration, True
|
|
253
|
+
)
|
|
256
254
|
# print(payload)
|
|
257
255
|
|
|
258
256
|
response = self._request(
|
|
@@ -265,9 +263,7 @@ class RedTeamClient(BaseClient):
|
|
|
265
263
|
raise RedTeamClientError(f"API Error: {str(response)}")
|
|
266
264
|
return RedTeamResponse.from_dict(response)
|
|
267
265
|
else:
|
|
268
|
-
raise RedTeamClientError(
|
|
269
|
-
"Please provide a endpoint configuration"
|
|
270
|
-
)
|
|
266
|
+
raise RedTeamClientError("Please provide a endpoint configuration")
|
|
271
267
|
|
|
272
268
|
def add_custom_task_with_saved_model(
|
|
273
269
|
self,
|
|
@@ -281,7 +277,7 @@ class RedTeamClient(BaseClient):
|
|
|
281
277
|
"""
|
|
282
278
|
if not model_saved_name:
|
|
283
279
|
raise RedTeamClientError("Please provide a model_saved_name")
|
|
284
|
-
|
|
280
|
+
|
|
285
281
|
if not model_version:
|
|
286
282
|
raise RedTeamClientError("Please provide a model_version. Default is 'v1'")
|
|
287
283
|
|
|
@@ -302,10 +298,7 @@ class RedTeamClient(BaseClient):
|
|
|
302
298
|
|
|
303
299
|
if config.dataset_configuration:
|
|
304
300
|
payload["dataset_configuration"] = DatasetClient.prepare_dataset_payload(
|
|
305
|
-
config.dataset_configuration, True
|
|
306
|
-
else:
|
|
307
|
-
raise RedTeamClientError(
|
|
308
|
-
"Please provide a dataset configuration"
|
|
301
|
+
config.dataset_configuration, True
|
|
309
302
|
)
|
|
310
303
|
|
|
311
304
|
headers = {
|
|
@@ -334,7 +327,7 @@ class RedTeamClient(BaseClient):
|
|
|
334
327
|
):
|
|
335
328
|
"""
|
|
336
329
|
Add a new custom red teaming task with v3 attack methods format.
|
|
337
|
-
|
|
330
|
+
|
|
338
331
|
V3 format supports nested attack methods:
|
|
339
332
|
{
|
|
340
333
|
"test_name": {
|
|
@@ -372,15 +365,13 @@ class RedTeamClient(BaseClient):
|
|
|
372
365
|
|
|
373
366
|
if config.dataset_configuration:
|
|
374
367
|
payload["dataset_configuration"] = DatasetClient.prepare_dataset_payload(
|
|
375
|
-
config.dataset_configuration, True
|
|
376
|
-
else:
|
|
377
|
-
raise RedTeamClientError(
|
|
378
|
-
"Please provide a dataset configuration"
|
|
368
|
+
config.dataset_configuration, True
|
|
379
369
|
)
|
|
380
370
|
|
|
381
371
|
if config.endpoint_configuration:
|
|
382
372
|
payload["endpoint_configuration"] = ModelClient.prepare_model_payload(
|
|
383
|
-
config.endpoint_configuration, True
|
|
373
|
+
config.endpoint_configuration, True
|
|
374
|
+
)
|
|
384
375
|
|
|
385
376
|
response = self._request(
|
|
386
377
|
"POST",
|
|
@@ -392,9 +383,7 @@ class RedTeamClient(BaseClient):
|
|
|
392
383
|
raise RedTeamClientError(f"API Error: {str(response)}")
|
|
393
384
|
return RedTeamResponse.from_dict(response)
|
|
394
385
|
else:
|
|
395
|
-
raise RedTeamClientError(
|
|
396
|
-
"Please provide a endpoint configuration"
|
|
397
|
-
)
|
|
386
|
+
raise RedTeamClientError("Please provide a endpoint configuration")
|
|
398
387
|
|
|
399
388
|
def add_custom_task_with_saved_model_v3(
|
|
400
389
|
self,
|
|
@@ -405,7 +394,7 @@ class RedTeamClient(BaseClient):
|
|
|
405
394
|
):
|
|
406
395
|
"""
|
|
407
396
|
Add a new red teaming custom task using a saved model with v3 attack methods format.
|
|
408
|
-
|
|
397
|
+
|
|
409
398
|
V3 format supports nested attack methods:
|
|
410
399
|
{
|
|
411
400
|
"test_name": {
|
|
@@ -422,7 +411,7 @@ class RedTeamClient(BaseClient):
|
|
|
422
411
|
"""
|
|
423
412
|
if not model_saved_name:
|
|
424
413
|
raise RedTeamClientError("Please provide a model_saved_name")
|
|
425
|
-
|
|
414
|
+
|
|
426
415
|
if not model_version:
|
|
427
416
|
raise RedTeamClientError("Please provide a model_version. Default is 'v1'")
|
|
428
417
|
|
|
@@ -439,13 +428,10 @@ class RedTeamClient(BaseClient):
|
|
|
439
428
|
# Only add frameworks if provided and not empty
|
|
440
429
|
if config.frameworks:
|
|
441
430
|
payload["frameworks"] = config.frameworks
|
|
442
|
-
|
|
431
|
+
print(config.__dict__)
|
|
443
432
|
if config.dataset_configuration:
|
|
444
433
|
payload["dataset_configuration"] = DatasetClient.prepare_dataset_payload(
|
|
445
|
-
config.dataset_configuration, True
|
|
446
|
-
else:
|
|
447
|
-
raise RedTeamClientError(
|
|
448
|
-
"Please provide a dataset configuration"
|
|
434
|
+
config.dataset_configuration, True
|
|
449
435
|
)
|
|
450
436
|
|
|
451
437
|
headers = {
|
|
@@ -457,6 +443,7 @@ class RedTeamClient(BaseClient):
|
|
|
457
443
|
if policy_name is not None:
|
|
458
444
|
headers["X-Enkrypt-Policy"] = policy_name
|
|
459
445
|
|
|
446
|
+
print("Request payload:", payload)
|
|
460
447
|
response = self._request(
|
|
461
448
|
"POST",
|
|
462
449
|
"/redteam/v3/model/add-custom-task",
|
|
@@ -477,13 +464,13 @@ class RedTeamClient(BaseClient):
|
|
|
477
464
|
|
|
478
465
|
Returns:
|
|
479
466
|
dict: The task status information
|
|
480
|
-
|
|
467
|
+
|
|
481
468
|
Raises:
|
|
482
469
|
RedTeamClientError: If neither task_id nor test_name is provided, or if there's an error from the API
|
|
483
470
|
"""
|
|
484
471
|
if not task_id and not test_name:
|
|
485
472
|
raise RedTeamClientError("Either task_id or test_name must be provided")
|
|
486
|
-
|
|
473
|
+
|
|
487
474
|
headers = {}
|
|
488
475
|
if task_id:
|
|
489
476
|
headers["X-Enkrypt-Task-ID"] = task_id
|
|
@@ -538,13 +525,13 @@ class RedTeamClient(BaseClient):
|
|
|
538
525
|
|
|
539
526
|
Returns:
|
|
540
527
|
dict: The task details and status
|
|
541
|
-
|
|
528
|
+
|
|
542
529
|
Raises:
|
|
543
530
|
RedTeamClientError: If neither task_id nor test_name is provided, or if there's an error from the API
|
|
544
531
|
"""
|
|
545
532
|
if not task_id and not test_name:
|
|
546
533
|
raise RedTeamClientError("Either task_id or test_name must be provided")
|
|
547
|
-
|
|
534
|
+
|
|
548
535
|
headers = {}
|
|
549
536
|
if task_id:
|
|
550
537
|
headers["X-Enkrypt-Task-ID"] = task_id
|
|
@@ -567,13 +554,13 @@ class RedTeamClient(BaseClient):
|
|
|
567
554
|
|
|
568
555
|
Returns:
|
|
569
556
|
dict: The summary of the task results
|
|
570
|
-
|
|
557
|
+
|
|
571
558
|
Raises:
|
|
572
559
|
RedTeamClientError: If neither task_id nor test_name is provided, or if there's an error from the API
|
|
573
560
|
"""
|
|
574
561
|
if not task_id and not test_name:
|
|
575
562
|
raise RedTeamClientError("Either task_id or test_name must be provided")
|
|
576
|
-
|
|
563
|
+
|
|
577
564
|
headers = {}
|
|
578
565
|
if task_id:
|
|
579
566
|
headers["X-Enkrypt-Task-ID"] = task_id
|
|
@@ -585,8 +572,10 @@ class RedTeamClient(BaseClient):
|
|
|
585
572
|
raise RedTeamClientError(f"API Error: {str(response)}")
|
|
586
573
|
# print(f"Response: {response}")
|
|
587
574
|
return RedTeamResultSummary.from_dict(response)
|
|
588
|
-
|
|
589
|
-
def get_result_summary_test_type(
|
|
575
|
+
|
|
576
|
+
def get_result_summary_test_type(
|
|
577
|
+
self, task_id: str = None, test_name: str = None, test_type: str = None
|
|
578
|
+
):
|
|
590
579
|
"""
|
|
591
580
|
Get the summary of results for a specific red teaming task for a specific test type.
|
|
592
581
|
|
|
@@ -597,16 +586,16 @@ class RedTeamClient(BaseClient):
|
|
|
597
586
|
|
|
598
587
|
Returns:
|
|
599
588
|
dict: The summary of the task results for the specified test type
|
|
600
|
-
|
|
589
|
+
|
|
601
590
|
Raises:
|
|
602
591
|
RedTeamClientError: If neither task_id nor test_name is provided, or if there's an error from the API
|
|
603
592
|
"""
|
|
604
593
|
if not task_id and not test_name:
|
|
605
594
|
raise RedTeamClientError("Either task_id or test_name must be provided")
|
|
606
|
-
|
|
595
|
+
|
|
607
596
|
if not test_type:
|
|
608
597
|
raise RedTeamClientError("test_type must be provided")
|
|
609
|
-
|
|
598
|
+
|
|
610
599
|
headers = {}
|
|
611
600
|
if task_id:
|
|
612
601
|
headers["X-Enkrypt-Task-ID"] = task_id
|
|
@@ -630,25 +619,27 @@ class RedTeamClient(BaseClient):
|
|
|
630
619
|
|
|
631
620
|
Returns:
|
|
632
621
|
dict: The detailed task results
|
|
633
|
-
|
|
622
|
+
|
|
634
623
|
Raises:
|
|
635
624
|
RedTeamClientError: If neither task_id nor test_name is provided, or if there's an error from the API
|
|
636
625
|
"""
|
|
637
626
|
if not task_id and not test_name:
|
|
638
627
|
raise RedTeamClientError("Either task_id or test_name must be provided")
|
|
639
|
-
|
|
628
|
+
|
|
640
629
|
headers = {}
|
|
641
630
|
if task_id:
|
|
642
631
|
headers["X-Enkrypt-Task-ID"] = task_id
|
|
643
632
|
if test_name:
|
|
644
633
|
headers["X-Enkrypt-Test-Name"] = test_name
|
|
645
|
-
|
|
634
|
+
|
|
646
635
|
response = self._request("GET", "/redteam/v3/results/details", headers=headers)
|
|
647
636
|
if response.get("error"):
|
|
648
637
|
raise RedTeamClientError(f"API Error: {str(response)}")
|
|
649
638
|
return RedTeamResultDetails.from_dict(response)
|
|
650
|
-
|
|
651
|
-
def get_result_details_test_type(
|
|
639
|
+
|
|
640
|
+
def get_result_details_test_type(
|
|
641
|
+
self, task_id: str = None, test_name: str = None, test_type: str = None
|
|
642
|
+
):
|
|
652
643
|
"""
|
|
653
644
|
Get the detailed results for a specific red teaming task for a specific test type.
|
|
654
645
|
|
|
@@ -659,16 +650,16 @@ class RedTeamClient(BaseClient):
|
|
|
659
650
|
|
|
660
651
|
Returns:
|
|
661
652
|
dict: The detailed task results
|
|
662
|
-
|
|
653
|
+
|
|
663
654
|
Raises:
|
|
664
655
|
RedTeamClientError: If neither task_id nor test_name is provided, or if there's an error from the API
|
|
665
656
|
"""
|
|
666
657
|
if not task_id and not test_name:
|
|
667
658
|
raise RedTeamClientError("Either task_id or test_name must be provided")
|
|
668
|
-
|
|
659
|
+
|
|
669
660
|
if not test_type:
|
|
670
661
|
raise RedTeamClientError("test_type must be provided")
|
|
671
|
-
|
|
662
|
+
|
|
672
663
|
headers = {}
|
|
673
664
|
if task_id:
|
|
674
665
|
headers["X-Enkrypt-Task-ID"] = task_id
|
|
@@ -700,26 +691,34 @@ class RedTeamClient(BaseClient):
|
|
|
700
691
|
raise RedTeamClientError(f"API Error: {str(response)}")
|
|
701
692
|
return RedTeamTaskList.from_dict(response)
|
|
702
693
|
|
|
703
|
-
def risk_mitigation_guardrails_policy(
|
|
694
|
+
def risk_mitigation_guardrails_policy(
|
|
695
|
+
self, config: RedTeamRiskMitigationGuardrailsPolicyConfig
|
|
696
|
+
):
|
|
704
697
|
"""
|
|
705
698
|
Get the guardrails policy generated for risk mitigation.
|
|
706
699
|
"""
|
|
707
700
|
config = RedTeamRiskMitigationGuardrailsPolicyConfig.from_dict(config)
|
|
708
701
|
payload = config.to_dict()
|
|
709
|
-
|
|
710
|
-
response = self._request(
|
|
702
|
+
|
|
703
|
+
response = self._request(
|
|
704
|
+
"POST", "/redteam/risk-mitigation/guardrails-policy", json=payload
|
|
705
|
+
)
|
|
711
706
|
if isinstance(response, dict) and response.get("error"):
|
|
712
707
|
raise RedTeamClientError(f"API Error: {str(response)}")
|
|
713
708
|
return RedTeamRiskMitigationGuardrailsPolicyResponse.from_dict(response)
|
|
714
709
|
|
|
715
|
-
def risk_mitigation_system_prompt(
|
|
710
|
+
def risk_mitigation_system_prompt(
|
|
711
|
+
self, config: RedTeamRiskMitigationSystemPromptConfig
|
|
712
|
+
):
|
|
716
713
|
"""
|
|
717
714
|
Get the system prompt generated for risk mitigation.
|
|
718
715
|
"""
|
|
719
716
|
config = RedTeamRiskMitigationSystemPromptConfig.from_dict(config)
|
|
720
717
|
payload = config.to_dict()
|
|
721
|
-
|
|
722
|
-
response = self._request(
|
|
718
|
+
|
|
719
|
+
response = self._request(
|
|
720
|
+
"POST", "/redteam/risk-mitigation/system-prompt", json=payload
|
|
721
|
+
)
|
|
723
722
|
if isinstance(response, dict) and response.get("error"):
|
|
724
723
|
raise RedTeamClientError(f"API Error: {str(response)}")
|
|
725
724
|
return RedTeamRiskMitigationSystemPromptResponse.from_dict(response)
|
|
@@ -727,20 +726,18 @@ class RedTeamClient(BaseClient):
|
|
|
727
726
|
def get_findings(self, redteam_summary):
|
|
728
727
|
"""
|
|
729
728
|
Get findings and insights based on red team summary data.
|
|
730
|
-
|
|
729
|
+
|
|
731
730
|
Parameters:
|
|
732
731
|
- redteam_summary (dict or ResultSummary): Red team test summary data
|
|
733
|
-
|
|
732
|
+
|
|
734
733
|
Returns:
|
|
735
734
|
- RedTeamFindingsResponse: Response from the API containing findings
|
|
736
735
|
"""
|
|
737
736
|
# Allow passing in either a dict or a ResultSummary instance
|
|
738
737
|
if hasattr(redteam_summary, "to_dict"):
|
|
739
738
|
redteam_summary = redteam_summary.to_dict()
|
|
740
|
-
|
|
741
|
-
payload = {
|
|
742
|
-
"redteam_summary": redteam_summary
|
|
743
|
-
}
|
|
739
|
+
|
|
740
|
+
payload = {"redteam_summary": redteam_summary}
|
|
744
741
|
|
|
745
742
|
try:
|
|
746
743
|
response = self._request("POST", "/redteam/findings", json=payload)
|
|
@@ -753,20 +750,20 @@ class RedTeamClient(BaseClient):
|
|
|
753
750
|
def get_download_link(self, task_id: str = None, test_name: str = None):
|
|
754
751
|
"""
|
|
755
752
|
Get a download link for red team test results.
|
|
756
|
-
|
|
753
|
+
|
|
757
754
|
Args:
|
|
758
755
|
task_id (str, optional): The ID of the task to get download link for
|
|
759
756
|
test_name (str, optional): The name of the test to get download link for
|
|
760
|
-
|
|
757
|
+
|
|
761
758
|
Returns:
|
|
762
759
|
RedTeamDownloadLinkResponse: Response containing download link and expiry information
|
|
763
|
-
|
|
760
|
+
|
|
764
761
|
Raises:
|
|
765
762
|
RedTeamClientError: If neither task_id nor test_name is provided, or if there's an error from the API
|
|
766
763
|
"""
|
|
767
764
|
if not task_id and not test_name:
|
|
768
765
|
raise RedTeamClientError("Either task_id or test_name must be provided")
|
|
769
|
-
|
|
766
|
+
|
|
770
767
|
headers = {}
|
|
771
768
|
if task_id:
|
|
772
769
|
headers["X-Enkrypt-Task-ID"] = task_id
|
|
@@ -780,4 +777,3 @@ class RedTeamClient(BaseClient):
|
|
|
780
777
|
return RedTeamDownloadLinkResponse.from_dict(response)
|
|
781
778
|
except Exception as e:
|
|
782
779
|
raise RedTeamClientError(str(e))
|
|
783
|
-
|
|
@@ -6,25 +6,25 @@ enkryptai_sdk/config.py,sha256=zUlWFr33JVz_kzUl3JalXeq-s1q0Qvyi4HBrGk0CTBU,9402
|
|
|
6
6
|
enkryptai_sdk/datasets.py,sha256=RQIR6spI2STXeVolYzBt6gPv6PD5AGh9krs16aKWdWA,6067
|
|
7
7
|
enkryptai_sdk/deployments.py,sha256=A7XZ2JwrMod9V4_aV8bFY_Soh9E3jHdwaTuJ9BwXuyk,4215
|
|
8
8
|
enkryptai_sdk/evals.py,sha256=BywyEgIT7xdJ58svO_sDNOMVowdB0RTGoAZPEbCnDVo,2595
|
|
9
|
-
enkryptai_sdk/guardrails.py,sha256=
|
|
9
|
+
enkryptai_sdk/guardrails.py,sha256=9lcc2PYH6PD3xvZ_SxQe4xU8WL2tXIfz1lLy0tLhsA0,22813
|
|
10
10
|
enkryptai_sdk/guardrails_old.py,sha256=SgzPZkTzbAPD9XfmYNG6M1-TrzbhDHpAkI3FjnVWS_s,6434
|
|
11
11
|
enkryptai_sdk/models.py,sha256=0R0I4KOq0aDNi5utabANot-E8dT9GqiSsgrcI9RULHM,8932
|
|
12
|
-
enkryptai_sdk/red_team.py,sha256=
|
|
12
|
+
enkryptai_sdk/red_team.py,sha256=3Fi2VE3slBEKU0_LCadMQm1Pm1Kp4Jx-MrwohqrqntM,28058
|
|
13
13
|
enkryptai_sdk/response.py,sha256=2WOyejMYK7lA7I3fyebd0oYhP4js5Q1favJAV_h9pmo,13604
|
|
14
|
-
enkryptai_sdk/dto/__init__.py,sha256=
|
|
14
|
+
enkryptai_sdk/dto/__init__.py,sha256=tv3VxFetFGVR0vDE2oybh38qBDkAmvo4-FXXG_RkScY,3094
|
|
15
15
|
enkryptai_sdk/dto/ai_proxy.py,sha256=clwMN4xdH8Zr55dnhilHbs-qaHRlCOrLPrij0Zd1Av0,11283
|
|
16
16
|
enkryptai_sdk/dto/base.py,sha256=y77kQL1X7389ifSVNc0E7CUFNxACh5AM3ml9YPon1KY,2822
|
|
17
17
|
enkryptai_sdk/dto/coc.py,sha256=9D5mmSdmC_guV75ml48PPLZD_zFa5FjxRwlTqHrmdak,5071
|
|
18
18
|
enkryptai_sdk/dto/common.py,sha256=lrWMu4FKUGCN2dbS9fT4yNtfiPm1cNN16J4eCe4_tBM,1812
|
|
19
|
-
enkryptai_sdk/dto/datasets.py,sha256=
|
|
19
|
+
enkryptai_sdk/dto/datasets.py,sha256=Ux72S2BoZ28-SpNA2C7P23W_wag6cvGvXvXeVHedvzk,7138
|
|
20
20
|
enkryptai_sdk/dto/deployments.py,sha256=v--UrwkuXP4xTsPbmVruYj-g3JEQXepBRQfr-Gsv3aA,11744
|
|
21
|
-
enkryptai_sdk/dto/guardrails.py,sha256=
|
|
22
|
-
enkryptai_sdk/dto/models.py,sha256=
|
|
23
|
-
enkryptai_sdk/dto/red_team.py,sha256=
|
|
21
|
+
enkryptai_sdk/dto/guardrails.py,sha256=_FWZ0AJOqw8tD75oajbv1FYyIrzJUN11dlMnb3X9sBE,58415
|
|
22
|
+
enkryptai_sdk/dto/models.py,sha256=Dj9VBG7tWnNqnjyX2KMJXIlst-9Obzb_AtvbQiklizA,16632
|
|
23
|
+
enkryptai_sdk/dto/red_team.py,sha256=_VR_L1fj4t0sKISaEoGxqUW3vA0lRAVMQejeFaQ70ho,40200
|
|
24
24
|
enkryptai_sdk/utils/__init__.py,sha256=SII0dz9SesrXt2zOR1xXErPYZGj3WyC9A9Pn_eOLsOg,710
|
|
25
25
|
enkryptai_sdk/utils/pagination.py,sha256=5t9qiDdxRA4uQywU4I4pp9OScqNBrEPmzKlPG-b-eVE,11149
|
|
26
|
-
enkryptai_sdk-1.0.
|
|
27
|
-
enkryptai_sdk-1.0.
|
|
28
|
-
enkryptai_sdk-1.0.
|
|
29
|
-
enkryptai_sdk-1.0.
|
|
30
|
-
enkryptai_sdk-1.0.
|
|
26
|
+
enkryptai_sdk-1.0.27.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
27
|
+
enkryptai_sdk-1.0.27.dist-info/METADATA,sha256=h8lXBiColUVvV1G6KYxx8sNmxbjXYTBk-Xg-UX0rH8o,1644
|
|
28
|
+
enkryptai_sdk-1.0.27.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
29
|
+
enkryptai_sdk-1.0.27.dist-info/top_level.txt,sha256=s2X9UJJwvJamNmr6ZXWyyQe60sXtQGWFuaBYfhgHI_4,14
|
|
30
|
+
enkryptai_sdk-1.0.27.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|