enkryptai-sdk 1.0.15__py3-none-any.whl → 1.0.16__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.
@@ -40,6 +40,7 @@ class ModelProviders(str, Enum):
40
40
  CUSTOM = "custom"
41
41
  HR = "hr"
42
42
  URL = "url"
43
+ ENKRYPTAI = "enkryptai"
43
44
 
44
45
 
45
46
  @dataclass
@@ -92,10 +93,11 @@ class ModelDetailConfig:
92
93
  # model_provider: str = "openai"
93
94
  model_provider: ModelProviders = ModelProviders.OPENAI
94
95
  system_prompt: str = ""
95
-
96
- endpoint_url: str = "https://api.openai.com/v1/chat/completions"
96
+ endpoint_url: str = ""
97
97
  auth_data: AuthData = field(default_factory=AuthData)
98
+ metadata: Dict[str, Any] = field(default_factory=dict)
98
99
  api_keys: Set[Optional[str]] = field(default_factory=lambda: {None})
100
+ _extra_fields: Dict[str, Any] = field(default_factory=dict)
99
101
 
100
102
 
101
103
  @dataclass
@@ -159,7 +161,7 @@ class ModelConfigDetails(BaseDTO):
159
161
  headers: str = ""
160
162
  system_prompt: str = ""
161
163
  hosting_type: str = "External"
162
- endpoint_url: str = "https://api.openai.com/v1/chat/completions"
164
+ endpoint_url: str = ""
163
165
  model_name: Optional[str] = ""
164
166
  apikey: Optional[str] = None
165
167
  paths: Optional[PathsConfig] = None
@@ -62,13 +62,59 @@ class RedTeamTaskStatus(BaseDTO):
62
62
  status: Optional[str] = None
63
63
 
64
64
 
65
+ @dataclass
66
+ class RedTeamTaskDetailsModelConfig(BaseDTO):
67
+ system_prompt: Optional[str] = None
68
+ model_version: Optional[str] = None
69
+ _extra_fields: Dict[str, Any] = field(default_factory=dict)
70
+
71
+ @classmethod
72
+ def from_dict(cls, data: Dict) -> "RedTeamTaskDetailsModelConfig":
73
+ return cls(
74
+ system_prompt=data.get("system_prompt"),
75
+ model_version=data.get("model_version"),
76
+ )
77
+
78
+ def to_dict(self) -> Dict:
79
+ return {
80
+ "system_prompt": self.system_prompt,
81
+ "model_version": self.model_version,
82
+ }
83
+
84
+
65
85
  @dataclass
66
86
  class RedTeamTaskDetails(BaseDTO):
67
87
  created_at: Optional[str] = None
88
+ model_saved_name: Optional[str] = None
68
89
  model_name: Optional[str] = None
69
90
  status: Optional[str] = None
70
91
  test_name: Optional[str] = None
71
92
  task_id: Optional[str] = None
93
+ model_config: Optional[RedTeamTaskDetailsModelConfig] = None
94
+ _extra_fields: Dict[str, Any] = field(default_factory=dict)
95
+
96
+ @classmethod
97
+ def from_dict(cls, data: Dict) -> "RedTeamTaskDetails":
98
+ return cls(
99
+ created_at=data.get("created_at"),
100
+ model_saved_name=data.get("model_saved_name"),
101
+ model_name=data.get("model_name"),
102
+ status=data.get("status"),
103
+ test_name=data.get("test_name"),
104
+ task_id=data.get("task_id"),
105
+ model_config=RedTeamTaskDetailsModelConfig.from_dict(data.get("model_config", {})),
106
+ )
107
+
108
+ def to_dict(self) -> Dict:
109
+ return {
110
+ "created_at": self.created_at,
111
+ "model_saved_name": self.model_saved_name,
112
+ "model_name": self.model_name,
113
+ "status": self.status,
114
+ "test_name": self.test_name,
115
+ "task_id": self.task_id,
116
+ "model_config": self.model_config.to_dict(),
117
+ }
72
118
 
73
119
 
74
120
  @dataclass
@@ -602,7 +648,7 @@ class RedTeamTaskList(BaseDTO):
602
648
 
603
649
  @dataclass
604
650
  class RedTeamRiskMitigationGuardrailsPolicyConfig(BaseDTO):
605
- required_detectors: List[RiskGuardrailDetectorsEnum] = field(default_factory=list)
651
+ # required_detectors: List[RiskGuardrailDetectorsEnum] = field(default_factory=list)
606
652
  redteam_summary: ResultSummary = field(default_factory=ResultSummary)
607
653
  _extra_fields: Dict[str, Any] = field(default_factory=dict)
608
654
 
@@ -611,14 +657,14 @@ class RedTeamRiskMitigationGuardrailsPolicyConfig(BaseDTO):
611
657
  data = data.copy()
612
658
  summary = ResultSummary.from_dict(data.pop("redteam_summary", {}))
613
659
  return cls(
614
- required_detectors=[RiskGuardrailDetectorsEnum(detector) for detector in data.get("required_detectors", [])],
660
+ # required_detectors=[RiskGuardrailDetectorsEnum(detector) for detector in data.get("required_detectors", [])],
615
661
  redteam_summary=summary,
616
662
  _extra_fields=data,
617
663
  )
618
664
 
619
665
  def to_dict(self) -> dict:
620
666
  return {
621
- "required_detectors": [detector.value for detector in self.required_detectors],
667
+ # "required_detectors": [detector.value for detector in self.required_detectors],
622
668
  "redteam_summary": self.redteam_summary.to_dict(),
623
669
  }
624
670
 
enkryptai_sdk/models.py CHANGED
@@ -29,17 +29,29 @@ class ModelClient(BaseClient):
29
29
  if isinstance(config, dict):
30
30
  config = ModelConfig.from_dict(config)
31
31
 
32
- # Parse endpoint_url into components
33
- parsed_url = urlparse(config.model_config.endpoint_url)
34
- path_parts = parsed_url.path.strip("/").split("/")
35
-
36
- # Extract base_path and endpoint path
37
- if len(path_parts) >= 1:
38
- base_path = path_parts[0] # Usually 'v1'
39
- remaining_path = "/".join(path_parts[1:]) # The rest of the path
40
- else:
41
- base_path = ""
42
- remaining_path = ""
32
+ endpoint_data = {}
33
+ base_path = ""
34
+ remaining_path = ""
35
+
36
+ if config.model_config.endpoint_url:
37
+ # Parse endpoint_url into components
38
+ parsed_url = urlparse(config.model_config.endpoint_url)
39
+ path_parts = parsed_url.path.strip("/").split("/")
40
+
41
+ # Extract base_path and endpoint path
42
+ if len(path_parts) >= 1:
43
+ base_path = path_parts[0] # Usually 'v1'
44
+ remaining_path = "/".join(path_parts[1:]) # The rest of the path
45
+ else:
46
+ base_path = ""
47
+ remaining_path = ""
48
+
49
+ endpoint_data = {
50
+ "scheme": parsed_url.scheme,
51
+ "host": parsed_url.hostname,
52
+ "port": parsed_url.port or (443 if parsed_url.scheme == "https" else 80),
53
+ "base_path": f"/{base_path}",
54
+ }
43
55
 
44
56
  if config.model_config.paths:
45
57
  paths = config.model_config.paths.to_dict()
@@ -61,12 +73,7 @@ class ModelClient(BaseClient):
61
73
  "hosting_type": config.model_config.hosting_type,
62
74
  "model_source": config.model_config.model_source,
63
75
  "system_prompt": config.model_config.system_prompt,
64
- "endpoint": {
65
- "scheme": parsed_url.scheme,
66
- "host": parsed_url.hostname,
67
- "port": parsed_url.port or (443 if parsed_url.scheme == "https" else 80),
68
- "base_path": f"/{base_path}",
69
- },
76
+ "endpoint": endpoint_data,
70
77
  "paths": paths,
71
78
  "auth_data": {
72
79
  "header_name": config.model_config.auth_data.header_name,
@@ -149,92 +156,33 @@ class ModelClient(BaseClient):
149
156
  except Exception as e:
150
157
  return {"error": str(e)}
151
158
 
152
- def modify_model(self, config: ModelConfig, old_model_saved_name=None, old_model_version=None) -> ModelResponse:
159
+ def modify_model(self, config: ModelConfig | dict, old_model_saved_name=None, old_model_version=None) -> ModelResponse:
153
160
  """
154
161
  Modify an existing model in the system.
155
162
 
156
163
  Args:
157
- old_model_saved_name (str): The old saved name of the model to modify
158
- old_model_version (str): The old version of the model to modify
159
- config (ModelConfig): Configuration object containing model details
164
+ config (Union[ModelConfig, dict]): Configuration object or dictionary containing model details
165
+ old_model_saved_name (str, optional): The old saved name of the model to modify. Defaults to None.
166
+ old_model_version (str, optional): The old version of the model to modify. Defaults to None.
160
167
 
161
168
  Returns:
162
169
  dict: Response from the API containing the modified model details
163
170
  """
171
+
172
+ temp_config = config
173
+ if isinstance(temp_config, dict):
174
+ temp_config = ModelConfig.from_dict(temp_config)
175
+
164
176
  if old_model_saved_name is None:
165
- old_model_saved_name = config["model_saved_name"]
177
+ old_model_saved_name = temp_config.model_saved_name
166
178
 
167
179
  if old_model_version is None:
168
- old_model_version = config["model_version"]
180
+ old_model_version = temp_config.model_version
169
181
 
170
182
  headers = {"Content-Type": "application/json", "X-Enkrypt-Model": old_model_saved_name, "X-Enkrypt-Model-Version": old_model_version}
171
- # print(config)
172
- config = ModelConfig.from_dict(config)
173
- # Parse endpoint_url into components
174
- parsed_url = urlparse(config.model_config.endpoint_url)
175
- path_parts = parsed_url.path.strip("/").split("/")
176
-
177
- # Extract base_path and endpoint path
178
- if len(path_parts) >= 1:
179
- base_path = path_parts[0] # Usually 'v1'
180
- remaining_path = "/".join(path_parts[1:]) # The rest of the path
181
- else:
182
- base_path = ""
183
- remaining_path = ""
184
-
185
- if config.model_config.paths:
186
- paths = config.model_config.paths.to_dict()
187
- else:
188
- # Determine paths based on the endpoint
189
- paths = {
190
- "completions": (
191
- f"/{remaining_path.split('/')[-1]}" if remaining_path else ""
192
- ),
193
- "chat": f"/{remaining_path}" if remaining_path else "",
194
- }
195
-
196
- # Convert custom_headers to list of dictionaries
197
- custom_headers = [header.to_dict() for header in config.model_config.custom_headers]
183
+
184
+ payload = self.prepare_model_payload(temp_config)
198
185
 
199
- payload = {
200
- "model_saved_name": config.model_saved_name,
201
- "model_version": config.model_version,
202
- "testing_for": config.testing_for,
203
- "model_name": config.model_name,
204
- "certifications": config.certifications,
205
- "model_config": {
206
- "model_provider": config.model_config.model_provider,
207
- "hosting_type": config.model_config.hosting_type,
208
- "model_source": config.model_config.model_source,
209
- "system_prompt": config.model_config.system_prompt,
210
- "endpoint": {
211
- "scheme": parsed_url.scheme,
212
- "host": parsed_url.hostname,
213
- "port": parsed_url.port
214
- or (443 if parsed_url.scheme == "https" else 80),
215
- "base_path": f"/{base_path}", # Just v1
216
- },
217
- "paths": paths,
218
- "auth_data": {
219
- "header_name": config.model_config.auth_data.header_name,
220
- "header_prefix": config.model_config.auth_data.header_prefix,
221
- "space_after_prefix": config.model_config.auth_data.space_after_prefix,
222
- },
223
- "apikeys": (
224
- [config.model_config.apikey] if config.model_config.apikey else []
225
- ),
226
- "tools": config.model_config.tools,
227
- "input_modalities": [m.value if hasattr(m, 'value') else m for m in config.model_config.input_modalities],
228
- "output_modalities": [m.value if hasattr(m, 'value') else m for m in config.model_config.output_modalities],
229
- "custom_curl_command": config.model_config.custom_curl_command,
230
- "custom_headers": custom_headers,
231
- "custom_payload": config.model_config.custom_payload,
232
- "custom_response_content_type": config.model_config.custom_response_content_type,
233
- "custom_response_format": config.model_config.custom_response_format,
234
- "metadata": config.model_config.metadata,
235
- "default_request_options": config.model_config.default_request_options,
236
- },
237
- }
238
186
  try:
239
187
  response = self._request(
240
188
  "PATCH", "/models/modify-model", headers=headers, json=payload
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: enkryptai-sdk
3
- Version: 1.0.15
3
+ Version: 1.0.16
4
4
  Summary: A Python SDK with guardrails and red teaming functionality for API interactions
5
5
  Home-page: https://github.com/enkryptai/enkryptai-sdk
6
6
  Author: Enkrypt AI Team
@@ -526,9 +526,6 @@ sample_custom_redteam_model_config = {
526
526
 
527
527
  ```python Python
528
528
  sample_redteam_risk_mitigation_guardrails_policy_config = {
529
- "required_detectors": [
530
- "policy_violation"
531
- ],
532
529
  "redteam_summary": {
533
530
  "category": [
534
531
  {
@@ -8,7 +8,7 @@ enkryptai_sdk/deployments.py,sha256=A7XZ2JwrMod9V4_aV8bFY_Soh9E3jHdwaTuJ9BwXuyk,
8
8
  enkryptai_sdk/evals.py,sha256=BywyEgIT7xdJ58svO_sDNOMVowdB0RTGoAZPEbCnDVo,2595
9
9
  enkryptai_sdk/guardrails.py,sha256=NluimOA0gM9N3S_q47LTUeG97t9PlYqPHlZahDPkJvI,16365
10
10
  enkryptai_sdk/guardrails_old.py,sha256=SgzPZkTzbAPD9XfmYNG6M1-TrzbhDHpAkI3FjnVWS_s,6434
11
- enkryptai_sdk/models.py,sha256=rrLTT3i96flWidVrr67j6VZ6XmkdxwEzlF4S4aoVmOQ,11559
11
+ enkryptai_sdk/models.py,sha256=OfADGvP2gy52_fXT5iAj81Q07iDGAEYWiKYLD_ycozU,8786
12
12
  enkryptai_sdk/red_team.py,sha256=cjN4LODbpYiECcoL0JROMcCPCzm3Ib6kXi7kQspP4hQ,19869
13
13
  enkryptai_sdk/response.py,sha256=43JRubzgGCpoVxYNzBZY0AlUgLbfcXD_AwD7wU3qY9o,4086
14
14
  enkryptai_sdk/dto/__init__.py,sha256=wHgIv_OCnVMJOys-vqImF59ifogDrMcgxVRmfNayVvc,2761
@@ -18,10 +18,10 @@ enkryptai_sdk/dto/coc.py,sha256=Lp2aat_24J4KuUg4BeJl9S39tEak8Bw15eJ4cQDrRQk,4749
18
18
  enkryptai_sdk/dto/datasets.py,sha256=RFA9CmbhD-QDDyweBq_k9iBd00b6I6SWmdP9DPNd9fc,5002
19
19
  enkryptai_sdk/dto/deployments.py,sha256=Aw4b8tDA3FYIomqDvCjblCXTagL4bT8Fx91X0SFXs40,11216
20
20
  enkryptai_sdk/dto/guardrails.py,sha256=oJQqFhsdQd_yPU187AhKse-Y4xktgmVNwwKKkzFazbg,50167
21
- enkryptai_sdk/dto/models.py,sha256=zldbvYV5zcg1J3UZh4UnaeM1cBx-_LCCyW-LtfBcjaQ,14246
22
- enkryptai_sdk/dto/red_team.py,sha256=7wtIFfcbWXw3w8aRWO4YMUwIvhwJX8XOJEyOv8Ls_eQ,23143
23
- enkryptai_sdk-1.0.15.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
- enkryptai_sdk-1.0.15.dist-info/METADATA,sha256=LcZpm1lqiwbrWYExhN26Fntjjm0PAFhcx_OYzzUbpYg,72934
25
- enkryptai_sdk-1.0.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
- enkryptai_sdk-1.0.15.dist-info/top_level.txt,sha256=s2X9UJJwvJamNmr6ZXWyyQe60sXtQGWFuaBYfhgHI_4,14
27
- enkryptai_sdk-1.0.15.dist-info/RECORD,,
21
+ enkryptai_sdk/dto/models.py,sha256=SDzNMwxDVIp2D1qO29ere8WgqC5n_bJuitesaoxitZo,14312
22
+ enkryptai_sdk/dto/red_team.py,sha256=EHwDbDM0mMLDyGB_kN4KEOO65ng9Bn51q9O3IdwO5Ng,24766
23
+ enkryptai_sdk-1.0.16.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
+ enkryptai_sdk-1.0.16.dist-info/METADATA,sha256=T7ws5lOF-ynN_Z3cegMX0Ysotjp2_n7pet8Ci-ULFmI,72860
25
+ enkryptai_sdk-1.0.16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
+ enkryptai_sdk-1.0.16.dist-info/top_level.txt,sha256=s2X9UJJwvJamNmr6ZXWyyQe60sXtQGWFuaBYfhgHI_4,14
27
+ enkryptai_sdk-1.0.16.dist-info/RECORD,,