enkryptai-sdk 1.0.23__py3-none-any.whl → 1.0.25__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/__init__.py +63 -5
- enkryptai_sdk/dto/__init__.py +9 -0
- enkryptai_sdk/dto/models.py +39 -0
- enkryptai_sdk/dto/red_team.py +261 -4
- enkryptai_sdk/red_team.py +222 -6
- enkryptai_sdk/response.py +271 -0
- enkryptai_sdk/utils/__init__.py +29 -0
- enkryptai_sdk/utils/pagination.py +384 -0
- {enkryptai_sdk-1.0.23.dist-info → enkryptai_sdk-1.0.25.dist-info}/METADATA +1 -1
- {enkryptai_sdk-1.0.23.dist-info → enkryptai_sdk-1.0.25.dist-info}/RECORD +13 -11
- {enkryptai_sdk-1.0.23.dist-info → enkryptai_sdk-1.0.25.dist-info}/WHEEL +0 -0
- {enkryptai_sdk-1.0.23.dist-info → enkryptai_sdk-1.0.25.dist-info}/licenses/LICENSE +0 -0
- {enkryptai_sdk-1.0.23.dist-info → enkryptai_sdk-1.0.25.dist-info}/top_level.txt +0 -0
enkryptai_sdk/__init__.py
CHANGED
|
@@ -7,22 +7,80 @@ from .red_team import RedTeamClient, RedTeamClientError
|
|
|
7
7
|
from .datasets import DatasetClient, DatasetClientError
|
|
8
8
|
from .deployments import DeploymentClient, DeploymentClientError
|
|
9
9
|
from .ai_proxy import AIProxyClient, AIProxyClientError
|
|
10
|
+
from .utils.pagination import (
|
|
11
|
+
PaginationInfo,
|
|
12
|
+
PaginatedResponse,
|
|
13
|
+
parse_pagination_params,
|
|
14
|
+
build_pagination_url,
|
|
15
|
+
create_paginated_response,
|
|
16
|
+
validate_pagination_params,
|
|
17
|
+
get_pagination_metadata,
|
|
18
|
+
calculate_page_info,
|
|
19
|
+
create_pagination_links,
|
|
20
|
+
apply_pagination_to_list,
|
|
21
|
+
format_pagination_response
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# Import DTOs
|
|
25
|
+
from .dto.models import (
|
|
26
|
+
ModelProviders,
|
|
27
|
+
AuthData,
|
|
28
|
+
BoxAIAuthData,
|
|
29
|
+
ModelConfigDetails,
|
|
30
|
+
DetailModelConfig,
|
|
31
|
+
ModelDetailConfig,
|
|
32
|
+
PathsConfig,
|
|
33
|
+
EndpointConfig,
|
|
34
|
+
ModelResponse,
|
|
35
|
+
InputModality,
|
|
36
|
+
OutputModality
|
|
37
|
+
)
|
|
10
38
|
|
|
11
39
|
__all__ = [
|
|
40
|
+
# Clients
|
|
12
41
|
"GuardrailsClient",
|
|
13
42
|
"GuardrailsClientError",
|
|
14
|
-
"
|
|
15
|
-
"CoCClient",
|
|
43
|
+
"CoCClient",
|
|
16
44
|
"CoCClientError",
|
|
17
45
|
"EvalsClient",
|
|
18
46
|
"ModelClient",
|
|
19
|
-
"RedTeamClient",
|
|
20
|
-
"DatasetClient",
|
|
21
|
-
"DeploymentClient",
|
|
22
47
|
"ModelClientError",
|
|
48
|
+
"RedTeamClient",
|
|
23
49
|
"RedTeamClientError",
|
|
50
|
+
"DatasetClient",
|
|
24
51
|
"DatasetClientError",
|
|
52
|
+
"DeploymentClient",
|
|
25
53
|
"DeploymentClientError",
|
|
26
54
|
"AIProxyClient",
|
|
27
55
|
"AIProxyClientError",
|
|
56
|
+
"EvalsClient",
|
|
57
|
+
|
|
58
|
+
# Config
|
|
59
|
+
"GuardrailsConfig",
|
|
60
|
+
|
|
61
|
+
# Pagination utilities
|
|
62
|
+
"PaginationInfo",
|
|
63
|
+
"PaginatedResponse",
|
|
64
|
+
"parse_pagination_params",
|
|
65
|
+
"build_pagination_url",
|
|
66
|
+
"create_paginated_response",
|
|
67
|
+
"validate_pagination_params",
|
|
68
|
+
"get_pagination_metadata",
|
|
69
|
+
"calculate_page_info",
|
|
70
|
+
"create_pagination_links",
|
|
71
|
+
"apply_pagination_to_list",
|
|
72
|
+
"format_pagination_response",
|
|
73
|
+
|
|
74
|
+
# DTOs
|
|
75
|
+
"ModelProviders",
|
|
76
|
+
"AuthData",
|
|
77
|
+
"BoxAIAuthData",
|
|
78
|
+
"ModelConfigDetails",
|
|
79
|
+
"DetailModelConfig",
|
|
80
|
+
"ModelDetailConfig",
|
|
81
|
+
"PathsConfig",
|
|
82
|
+
"EndpointConfig",
|
|
83
|
+
"ModelResponse",
|
|
84
|
+
"InputModality",
|
|
85
|
+
"OutputModality"
|
|
28
86
|
]
|
enkryptai_sdk/dto/__init__.py
CHANGED
|
@@ -10,6 +10,7 @@ from .coc import *
|
|
|
10
10
|
__all__ = [
|
|
11
11
|
"RedteamHealthResponse",
|
|
12
12
|
"RedTeamModelHealthConfig",
|
|
13
|
+
"RedTeamModelHealthConfigV3",
|
|
13
14
|
"RedteamModelHealthResponse",
|
|
14
15
|
"DetailModelConfig",
|
|
15
16
|
"ModelConfig",
|
|
@@ -25,6 +26,14 @@ __all__ = [
|
|
|
25
26
|
"DEFAULT_REDTEAM_CONFIG_WITH_SAVED_MODEL",
|
|
26
27
|
"DEFAULT_CUSTOM_REDTEAM_CONFIG",
|
|
27
28
|
"DEFAULT_CUSTOM_REDTEAM_CONFIG_WITH_SAVED_MODEL",
|
|
29
|
+
# V3 additions
|
|
30
|
+
"AttackMethodsV3",
|
|
31
|
+
"TestConfigV3",
|
|
32
|
+
"RedTeamTestConfigurationsV3",
|
|
33
|
+
"RedTeamCustomConfigV3",
|
|
34
|
+
"RedTeamCustomConfigWithSavedModelV3",
|
|
35
|
+
"DEFAULT_CUSTOM_REDTEAM_CONFIG_V3",
|
|
36
|
+
"DEFAULT_CUSTOM_REDTEAM_CONFIG_WITH_SAVED_MODEL_V3",
|
|
28
37
|
"ADVANCED_REDTEAM_TESTS",
|
|
29
38
|
"DETAIL_MODEL_CONFIG",
|
|
30
39
|
"DatasetConfig",
|
enkryptai_sdk/dto/models.py
CHANGED
|
@@ -42,6 +42,7 @@ class ModelProviders(str, Enum):
|
|
|
42
42
|
HR = "hr"
|
|
43
43
|
URL = "url"
|
|
44
44
|
ENKRYPTAI = "enkryptai"
|
|
45
|
+
BOXAI = "boxai"
|
|
45
46
|
|
|
46
47
|
|
|
47
48
|
@dataclass
|
|
@@ -88,6 +89,44 @@ class AuthData(BaseDTO):
|
|
|
88
89
|
return cls(**data)
|
|
89
90
|
|
|
90
91
|
|
|
92
|
+
@dataclass
|
|
93
|
+
class BoxAIAuthData(AuthData):
|
|
94
|
+
"""BoxAI-specific authentication data."""
|
|
95
|
+
boxai_client_id: Optional[str] = None
|
|
96
|
+
boxai_client_secret: Optional[str] = None
|
|
97
|
+
boxai_user_id: Optional[str] = None
|
|
98
|
+
boxai_default_file_id: Optional[str] = None
|
|
99
|
+
|
|
100
|
+
def __post_init__(self):
|
|
101
|
+
# Store BoxAI fields in extra_fields for backward compatibility
|
|
102
|
+
if self.boxai_client_id:
|
|
103
|
+
self._extra_fields["boxai_client_id"] = self.boxai_client_id
|
|
104
|
+
if self.boxai_client_secret:
|
|
105
|
+
self._extra_fields["boxai_client_secret"] = self.boxai_client_secret
|
|
106
|
+
if self.boxai_user_id:
|
|
107
|
+
self._extra_fields["boxai_user_id"] = self.boxai_user_id
|
|
108
|
+
if self.boxai_default_file_id:
|
|
109
|
+
self._extra_fields["boxai_default_file_id"] = self.boxai_default_file_id
|
|
110
|
+
|
|
111
|
+
@classmethod
|
|
112
|
+
def from_dict(cls, data: dict):
|
|
113
|
+
# Extract BoxAI fields from extra_fields if they exist
|
|
114
|
+
boxai_data = {}
|
|
115
|
+
if "_extra_fields" in data:
|
|
116
|
+
extra_fields = data["_extra_fields"]
|
|
117
|
+
for field in ["boxai_client_id", "boxai_client_secret", "boxai_user_id", "boxai_default_file_id"]:
|
|
118
|
+
if field in extra_fields:
|
|
119
|
+
boxai_data[field] = extra_fields[field]
|
|
120
|
+
|
|
121
|
+
# Merge with direct field values
|
|
122
|
+
for field in ["boxai_client_id", "boxai_client_secret", "boxai_user_id", "boxai_default_file_id"]:
|
|
123
|
+
if field in data:
|
|
124
|
+
boxai_data[field] = data[field]
|
|
125
|
+
|
|
126
|
+
# Create the instance
|
|
127
|
+
return cls(**boxai_data)
|
|
128
|
+
|
|
129
|
+
|
|
91
130
|
@dataclass
|
|
92
131
|
class ModelDetailConfig:
|
|
93
132
|
model_source: str = ""
|
enkryptai_sdk/dto/red_team.py
CHANGED
|
@@ -334,10 +334,12 @@ class RedTeamResultDetails(BaseDTO):
|
|
|
334
334
|
@dataclass
|
|
335
335
|
class AttackMethods(BaseDTO):
|
|
336
336
|
basic: List[str] = field(default_factory=lambda: ["basic"])
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
337
|
+
advanced: Dict[str, List[str]] = field(
|
|
338
|
+
default_factory=lambda: {
|
|
339
|
+
"static": ["masking", "figstep", "hades","encoding", "single_shot", "echo", "speed", "pitch", "reverb", "noise" ],
|
|
340
|
+
"dynamic": ["iterative","jood"]
|
|
341
|
+
}
|
|
342
|
+
)
|
|
341
343
|
|
|
342
344
|
def to_dict(self) -> dict:
|
|
343
345
|
return asdict(self)
|
|
@@ -391,6 +393,7 @@ class RedTeamTestConfigurations(BaseDTO):
|
|
|
391
393
|
# Basic tests
|
|
392
394
|
bias_test: TestConfig = field(default=None)
|
|
393
395
|
cbrn_test: TestConfig = field(default=None)
|
|
396
|
+
csem_test: TestConfig = field(default=None)
|
|
394
397
|
insecure_code_test: TestConfig = field(default=None)
|
|
395
398
|
toxicity_test: TestConfig = field(default=None)
|
|
396
399
|
harmful_test: TestConfig = field(default=None)
|
|
@@ -514,6 +517,60 @@ class RedTeamModelHealthConfig(BaseDTO):
|
|
|
514
517
|
)
|
|
515
518
|
|
|
516
519
|
|
|
520
|
+
@dataclass
|
|
521
|
+
class RedTeamModelHealthConfigV3(BaseDTO):
|
|
522
|
+
"""
|
|
523
|
+
V3 format for model health check that accepts endpoint_configuration
|
|
524
|
+
similar to add_custom_task.
|
|
525
|
+
"""
|
|
526
|
+
endpoint_configuration: ModelConfig = field(
|
|
527
|
+
default_factory=ModelConfig
|
|
528
|
+
)
|
|
529
|
+
|
|
530
|
+
def to_dict(self) -> dict:
|
|
531
|
+
d = asdict(self)
|
|
532
|
+
d["endpoint_configuration"] = self.endpoint_configuration.to_dict()
|
|
533
|
+
return d
|
|
534
|
+
|
|
535
|
+
@classmethod
|
|
536
|
+
def from_dict(cls, data: dict):
|
|
537
|
+
data = data.copy()
|
|
538
|
+
endpoint_config = ModelConfig.from_dict(
|
|
539
|
+
data.pop("endpoint_configuration", {})
|
|
540
|
+
)
|
|
541
|
+
return cls(
|
|
542
|
+
endpoint_configuration=endpoint_config,
|
|
543
|
+
)
|
|
544
|
+
|
|
545
|
+
def to_target_model_configuration(self) -> TargetModelConfiguration:
|
|
546
|
+
"""
|
|
547
|
+
Convert endpoint_configuration to target_model_configuration format.
|
|
548
|
+
This enables the V3 format to be compatible with the existing backend API.
|
|
549
|
+
"""
|
|
550
|
+
model_config = self.endpoint_configuration.model_config
|
|
551
|
+
|
|
552
|
+
return TargetModelConfiguration(
|
|
553
|
+
testing_for=self.endpoint_configuration.testing_for,
|
|
554
|
+
system_prompt=model_config.system_prompt,
|
|
555
|
+
model_source=model_config.model_source,
|
|
556
|
+
model_provider=model_config.model_provider.value if hasattr(model_config.model_provider, 'value') else model_config.model_provider,
|
|
557
|
+
model_endpoint_url=model_config.endpoint_url,
|
|
558
|
+
rate_per_min=model_config.rate_per_min,
|
|
559
|
+
model_name=self.endpoint_configuration.model_name,
|
|
560
|
+
model_version=self.endpoint_configuration.model_version,
|
|
561
|
+
model_auth_type=model_config.model_auth_type,
|
|
562
|
+
model_jwt_config=model_config.model_jwt_config,
|
|
563
|
+
model_api_key=model_config.apikey,
|
|
564
|
+
input_modalities=[InputModality(m) if isinstance(m, str) else m for m in model_config.input_modalities],
|
|
565
|
+
output_modalities=[OutputModality(m) if isinstance(m, str) else m for m in model_config.output_modalities],
|
|
566
|
+
custom_curl_command=model_config.custom_curl_command,
|
|
567
|
+
custom_headers=model_config.custom_headers,
|
|
568
|
+
custom_payload=model_config.custom_payload,
|
|
569
|
+
custom_response_content_type=model_config.custom_response_content_type,
|
|
570
|
+
custom_response_format=model_config.custom_response_format,
|
|
571
|
+
)
|
|
572
|
+
|
|
573
|
+
|
|
517
574
|
@dataclass
|
|
518
575
|
class RedteamModelHealthResponse(BaseDTO):
|
|
519
576
|
status: str
|
|
@@ -609,6 +666,7 @@ class RedTeamConfigWithSavedModel(BaseDTO):
|
|
|
609
666
|
@dataclass
|
|
610
667
|
class RedTeamCustomConfig(BaseDTO):
|
|
611
668
|
test_name: str = "Test Name"
|
|
669
|
+
frameworks: List[str] = field(default_factory=list)
|
|
612
670
|
|
|
613
671
|
redteam_test_configurations: RedTeamTestConfigurations = field(
|
|
614
672
|
default_factory=RedTeamTestConfigurations
|
|
@@ -651,6 +709,7 @@ class RedTeamCustomConfig(BaseDTO):
|
|
|
651
709
|
@dataclass
|
|
652
710
|
class RedTeamCustomConfigWithSavedModel(BaseDTO):
|
|
653
711
|
test_name: str = "Test Name"
|
|
712
|
+
frameworks: List[str] = field(default_factory=list)
|
|
654
713
|
|
|
655
714
|
redteam_test_configurations: RedTeamTestConfigurations = field(
|
|
656
715
|
default_factory=RedTeamTestConfigurations
|
|
@@ -847,6 +906,201 @@ class RedTeamFindingsResponse(BaseDTO):
|
|
|
847
906
|
return result
|
|
848
907
|
|
|
849
908
|
|
|
909
|
+
@dataclass
|
|
910
|
+
class RedTeamDownloadLinkResponse(BaseDTO):
|
|
911
|
+
link: str = ""
|
|
912
|
+
expiry: str = ""
|
|
913
|
+
expires_at: str = ""
|
|
914
|
+
_extra_fields: Dict[str, Any] = field(default_factory=dict)
|
|
915
|
+
|
|
916
|
+
@classmethod
|
|
917
|
+
def from_dict(cls, data: Dict[str, Any]) -> "RedTeamDownloadLinkResponse":
|
|
918
|
+
return cls(
|
|
919
|
+
link=data.get("link", ""),
|
|
920
|
+
expiry=data.get("expiry", ""),
|
|
921
|
+
expires_at=data.get("expires_at", "")
|
|
922
|
+
)
|
|
923
|
+
|
|
924
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
925
|
+
result = {
|
|
926
|
+
"link": self.link,
|
|
927
|
+
"expiry": self.expiry,
|
|
928
|
+
"expires_at": self.expires_at
|
|
929
|
+
}
|
|
930
|
+
result.update(self._extra_fields)
|
|
931
|
+
return result
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
# V3 Attack Methods and Test Configurations
|
|
935
|
+
@dataclass
|
|
936
|
+
class AttackMethodsV3(BaseDTO):
|
|
937
|
+
"""
|
|
938
|
+
V3 format for attack methods with nested structure:
|
|
939
|
+
{
|
|
940
|
+
"method_category": {
|
|
941
|
+
"method_name": {
|
|
942
|
+
"params": {}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
"""
|
|
947
|
+
_data: Dict[str, Dict[str, Dict[str, Any]]] = field(default_factory=dict)
|
|
948
|
+
|
|
949
|
+
def to_dict(self) -> dict:
|
|
950
|
+
return self._data
|
|
951
|
+
|
|
952
|
+
@classmethod
|
|
953
|
+
def from_dict(cls, data: dict):
|
|
954
|
+
return cls(_data=data)
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
@dataclass
|
|
958
|
+
class TestConfigV3(BaseDTO):
|
|
959
|
+
sample_percentage: int = 5
|
|
960
|
+
attack_methods: AttackMethodsV3 = field(default_factory=AttackMethodsV3)
|
|
961
|
+
|
|
962
|
+
def to_dict(self) -> dict:
|
|
963
|
+
return {
|
|
964
|
+
"sample_percentage": self.sample_percentage,
|
|
965
|
+
"attack_methods": self.attack_methods.to_dict(),
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
@classmethod
|
|
969
|
+
def from_dict(cls, data: dict):
|
|
970
|
+
attack_methods = AttackMethodsV3.from_dict(data.get("attack_methods", {}))
|
|
971
|
+
return cls(
|
|
972
|
+
sample_percentage=data.get("sample_percentage", 5),
|
|
973
|
+
attack_methods=attack_methods
|
|
974
|
+
)
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
@dataclass
|
|
978
|
+
class RedTeamTestConfigurationsV3(BaseDTO):
|
|
979
|
+
"""V3 format for red team test configurations with nested attack methods"""
|
|
980
|
+
# Basic tests
|
|
981
|
+
bias_test: TestConfigV3 = field(default=None)
|
|
982
|
+
cbrn_test: TestConfigV3 = field(default=None)
|
|
983
|
+
csem_test: TestConfigV3 = field(default=None)
|
|
984
|
+
insecure_code_test: TestConfigV3 = field(default=None)
|
|
985
|
+
toxicity_test: TestConfigV3 = field(default=None)
|
|
986
|
+
harmful_test: TestConfigV3 = field(default=None)
|
|
987
|
+
pii_test: TestConfigV3 = field(default=None)
|
|
988
|
+
copyright_test: TestConfigV3 = field(default=None)
|
|
989
|
+
misinformation_test: TestConfigV3 = field(default=None)
|
|
990
|
+
system_prompt_extractions_test: TestConfigV3 = field(default=None)
|
|
991
|
+
sponge_test: TestConfigV3 = field(default=None)
|
|
992
|
+
# Advanced tests
|
|
993
|
+
adv_info_test: TestConfigV3 = field(default=None)
|
|
994
|
+
adv_bias_test: TestConfigV3 = field(default=None)
|
|
995
|
+
adv_tool_test: TestConfigV3 = field(default=None)
|
|
996
|
+
adv_command_test: TestConfigV3 = field(default=None)
|
|
997
|
+
adv_pii_test: TestConfigV3 = field(default=None)
|
|
998
|
+
adv_competitor_test: TestConfigV3 = field(default=None)
|
|
999
|
+
# Custom tests
|
|
1000
|
+
custom_test: TestConfigV3 = field(default=None)
|
|
1001
|
+
# Agents tests
|
|
1002
|
+
alignment_and_governance_test: TestConfigV3 = field(default=None)
|
|
1003
|
+
input_and_content_integrity_test: TestConfigV3 = field(default=None)
|
|
1004
|
+
infrastructure_and_integration_test: TestConfigV3 = field(default=None)
|
|
1005
|
+
security_and_privacy_test: TestConfigV3 = field(default=None)
|
|
1006
|
+
human_factors_and_societal_impact_test: TestConfigV3 = field(default=None)
|
|
1007
|
+
access_control_test: TestConfigV3 = field(default=None)
|
|
1008
|
+
physical_and_actuation_safety_test: TestConfigV3 = field(default=None)
|
|
1009
|
+
reliability_and_monitoring_test: TestConfigV3 = field(default=None)
|
|
1010
|
+
governance_test: TestConfigV3 = field(default=None)
|
|
1011
|
+
agent_output_quality_test: TestConfigV3 = field(default=None)
|
|
1012
|
+
tool_misuse_test: TestConfigV3 = field(default=None)
|
|
1013
|
+
privacy_test: TestConfigV3 = field(default=None)
|
|
1014
|
+
reliability_and_observability_test: TestConfigV3 = field(default=None)
|
|
1015
|
+
agent_behaviour_test: TestConfigV3 = field(default=None)
|
|
1016
|
+
access_control_and_permissions_test: TestConfigV3 = field(default=None)
|
|
1017
|
+
tool_extraction_test: TestConfigV3 = field(default=None)
|
|
1018
|
+
_extra_fields: Dict[str, Any] = field(default_factory=dict)
|
|
1019
|
+
|
|
1020
|
+
@classmethod
|
|
1021
|
+
def from_dict(cls, data: dict):
|
|
1022
|
+
return cls(**{k: TestConfigV3.from_dict(v) if isinstance(v, dict) else v for k, v in data.items()})
|
|
1023
|
+
|
|
1024
|
+
|
|
1025
|
+
@dataclass
|
|
1026
|
+
class RedTeamCustomConfigV3(BaseDTO):
|
|
1027
|
+
test_name: str = "Test Name"
|
|
1028
|
+
frameworks: List[str] = field(default_factory=list)
|
|
1029
|
+
|
|
1030
|
+
redteam_test_configurations: RedTeamTestConfigurationsV3 = field(
|
|
1031
|
+
default_factory=RedTeamTestConfigurationsV3
|
|
1032
|
+
)
|
|
1033
|
+
dataset_configuration: DatasetConfig = field(
|
|
1034
|
+
default_factory=DatasetConfig
|
|
1035
|
+
)
|
|
1036
|
+
endpoint_configuration: ModelConfig = field(
|
|
1037
|
+
default_factory=ModelConfig
|
|
1038
|
+
)
|
|
1039
|
+
|
|
1040
|
+
_extra_fields: Dict[str, Any] = field(default_factory=dict)
|
|
1041
|
+
|
|
1042
|
+
def to_dict(self) -> dict:
|
|
1043
|
+
d = asdict(self)
|
|
1044
|
+
d["redteam_test_configurations"] = self.redteam_test_configurations.to_dict()
|
|
1045
|
+
d["dataset_configuration"] = self.dataset_configuration.to_dict()
|
|
1046
|
+
d["endpoint_configuration"] = self.endpoint_configuration.to_dict()
|
|
1047
|
+
return d
|
|
1048
|
+
|
|
1049
|
+
@classmethod
|
|
1050
|
+
def from_dict(cls, data: dict):
|
|
1051
|
+
data = data.copy()
|
|
1052
|
+
test_configs = RedTeamTestConfigurationsV3.from_dict(
|
|
1053
|
+
data.pop("redteam_test_configurations", {})
|
|
1054
|
+
)
|
|
1055
|
+
dataset_config = DatasetConfig.from_dict(
|
|
1056
|
+
data.pop("dataset_configuration", {})
|
|
1057
|
+
)
|
|
1058
|
+
endpoint_config = ModelConfig.from_dict(
|
|
1059
|
+
data.pop("endpoint_configuration", {})
|
|
1060
|
+
)
|
|
1061
|
+
return cls(
|
|
1062
|
+
**data,
|
|
1063
|
+
redteam_test_configurations=test_configs,
|
|
1064
|
+
dataset_configuration=dataset_config,
|
|
1065
|
+
endpoint_configuration=endpoint_config,
|
|
1066
|
+
)
|
|
1067
|
+
|
|
1068
|
+
|
|
1069
|
+
@dataclass
|
|
1070
|
+
class RedTeamCustomConfigWithSavedModelV3(BaseDTO):
|
|
1071
|
+
test_name: str = "Test Name"
|
|
1072
|
+
frameworks: List[str] = field(default_factory=list)
|
|
1073
|
+
|
|
1074
|
+
redteam_test_configurations: RedTeamTestConfigurationsV3 = field(
|
|
1075
|
+
default_factory=RedTeamTestConfigurationsV3
|
|
1076
|
+
)
|
|
1077
|
+
dataset_configuration: DatasetConfig = field(
|
|
1078
|
+
default_factory=DatasetConfig
|
|
1079
|
+
)
|
|
1080
|
+
|
|
1081
|
+
_extra_fields: Dict[str, Any] = field(default_factory=dict)
|
|
1082
|
+
|
|
1083
|
+
def to_dict(self) -> dict:
|
|
1084
|
+
d = asdict(self)
|
|
1085
|
+
d["redteam_test_configurations"] = self.redteam_test_configurations.to_dict()
|
|
1086
|
+
d["dataset_configuration"] = self.dataset_configuration.to_dict()
|
|
1087
|
+
return d
|
|
1088
|
+
|
|
1089
|
+
@classmethod
|
|
1090
|
+
def from_dict(cls, data: dict):
|
|
1091
|
+
data = data.copy()
|
|
1092
|
+
test_configs = RedTeamTestConfigurationsV3.from_dict(
|
|
1093
|
+
data.pop("redteam_test_configurations", {})
|
|
1094
|
+
)
|
|
1095
|
+
dataset_config = DatasetConfig.from_dict(
|
|
1096
|
+
data.pop("dataset_configuration", {})
|
|
1097
|
+
)
|
|
1098
|
+
return cls(
|
|
1099
|
+
**data,
|
|
1100
|
+
redteam_test_configurations=test_configs,
|
|
1101
|
+
dataset_configuration=dataset_config,
|
|
1102
|
+
)
|
|
1103
|
+
|
|
850
1104
|
|
|
851
1105
|
# Default configurations
|
|
852
1106
|
DEFAULT_REDTEAM_CONFIG = RedTeamConfig()
|
|
@@ -854,3 +1108,6 @@ DEFAULT_REDTEAM_CONFIG_WITH_SAVED_MODEL = RedTeamConfigWithSavedModel()
|
|
|
854
1108
|
|
|
855
1109
|
DEFAULT_CUSTOM_REDTEAM_CONFIG = RedTeamCustomConfig()
|
|
856
1110
|
DEFAULT_CUSTOM_REDTEAM_CONFIG_WITH_SAVED_MODEL = RedTeamCustomConfigWithSavedModel()
|
|
1111
|
+
|
|
1112
|
+
DEFAULT_CUSTOM_REDTEAM_CONFIG_V3 = RedTeamCustomConfigV3()
|
|
1113
|
+
DEFAULT_CUSTOM_REDTEAM_CONFIG_WITH_SAVED_MODEL_V3 = RedTeamCustomConfigWithSavedModelV3()
|