enkryptai-sdk 1.0.1__py3-none-any.whl → 1.0.2__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/ai_proxy.py CHANGED
@@ -46,24 +46,41 @@ class AIProxyClient(BaseClient):
46
46
  "POST", "/ai-proxy/chat/completions", headers=headers, json=payload
47
47
  )
48
48
 
49
+ # print("Response from API: ", response)
50
+
49
51
  if response.get("error"):
50
52
  error_message = response["error"]
51
53
  is_json_str = error_message.startswith("{") and error_message.endswith("}")
52
54
  # Try to parse nested JSON error if it's a string
53
55
  if isinstance(error_message, str) and is_json_str:
56
+ import ast
54
57
  import json
55
58
  try:
56
- error_message = json.loads(error_message.replace("'", '"'))
57
- response["error"] = error_message.get("error", error_message)
59
+ # # Using ast.literal_eval to safely evaluate the string as a Python literal
60
+ # # As json.loads is not working with literal string representation of dict
61
+ # parsed_error = json.loads(error_message.replace("'", '"'))
62
+ # # Convert Python string representation to proper dict
63
+ parsed_error = ast.literal_eval(response["error"])
64
+ # # Preserve both error and enkrypt_policy_detections fields
65
+ response["error"] = parsed_error.get("error", parsed_error)
66
+ if "enkrypt_policy_detections" in parsed_error:
67
+ response["enkrypt_policy_detections"] = parsed_error["enkrypt_policy_detections"]
58
68
  except json.JSONDecodeError:
59
69
  # If parsing fails, keep the original error
60
70
  pass
61
71
 
62
72
  # print("Error in response: ", response)
63
73
  if return_error:
64
- if is_json_str:
74
+ # if is_json_str:
75
+ # return ChatCompletionErrorResponse.from_dict(response)
76
+ # else:
77
+ # return ChatCompletionDirectErrorResponse.from_dict(response)
78
+ try:
79
+ # print("Error in response: ", response)
65
80
  return ChatCompletionErrorResponse.from_dict(response)
66
- else:
81
+ except (json.JSONDecodeError, TypeError, ValueError, SyntaxError):
82
+ # Fallback to direct error if error object can't be parsed
83
+ print("Failed to parse error response: ", response)
67
84
  return ChatCompletionDirectErrorResponse.from_dict(response)
68
85
  raise AIProxyClientError(response["error"])
69
86
 
@@ -262,6 +262,7 @@ class ChatCompletionError(BaseDTO):
262
262
  @dataclass
263
263
  class ChatCompletionErrorResponse(BaseDTO):
264
264
  error: ChatCompletionError
265
+ enkrypt_policy_detections: Dict[str, Any] = field(default_factory=dict)
265
266
  _extra_fields: Dict[str, Any] = field(default_factory=dict)
266
267
 
267
268
  @classmethod
@@ -270,16 +271,18 @@ class ChatCompletionErrorResponse(BaseDTO):
270
271
 
271
272
  # Create a copy of the data without the fields we're explicitly processing
272
273
  extra_fields = {k: v for k, v in data.items()
273
- if k not in ["error"]}
274
+ if k not in ["error", "enkrypt_policy_detections"]}
274
275
 
275
276
  return cls(
276
277
  error=ChatCompletionError.from_dict(error_data),
278
+ enkrypt_policy_detections=data.get("enkrypt_policy_detections", {}),
277
279
  _extra_fields=extra_fields
278
280
  )
279
281
 
280
282
  def to_dict(self) -> Dict[str, Any]:
281
283
  result = {
282
- "error": self.error.to_dict()
284
+ "error": self.error.to_dict(),
285
+ "enkrypt_policy_detections": self.enkrypt_policy_detections
283
286
  }
284
287
 
285
288
  # Add any extra fields
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: enkryptai-sdk
3
- Version: 1.0.1
3
+ Version: 1.0.2
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
@@ -21,6 +21,7 @@ Dynamic: license-file
21
21
  Dynamic: requires-python
22
22
  Dynamic: summary
23
23
 
24
+ ![Python SDK test](https://github.com/enkryptai/enkryptai-sdk/actions/workflows/test.yaml/badge.svg)
24
25
  # Enkrypt AI Python SDK
25
26
 
26
27
  A Python SDK with Guardrails, Models, Deployments, AI Proxy, Datasets and Red Team functionality for API interactions.
@@ -1,5 +1,5 @@
1
1
  enkryptai_sdk/__init__.py,sha256=rP6PtntJogJauj1lKWK8DkiBr3uYjireIUamr6aflu0,763
2
- enkryptai_sdk/ai_proxy.py,sha256=nwndIHNtCdvCOJwhkTOxtDHocbUta4cwtF1NrLkVg_I,2572
2
+ enkryptai_sdk/ai_proxy.py,sha256=QnfRlyKKjUfDuJ19rTM8dtbWvBaHgLyb2Z9AOjK2PFA,3723
3
3
  enkryptai_sdk/base.py,sha256=MlEDcEIjXo35kat9XkGUu7VB2fIvJk38C94wAeO9bEw,1304
4
4
  enkryptai_sdk/config.py,sha256=IpB8_aO4zXdvv061v24oh83oyJ5Tp1QBQTzeuW4h9QY,8828
5
5
  enkryptai_sdk/datasets.py,sha256=xekcdY9wIniw2TnylaK6o1RNZ5DRoluNOGawBkVgaM0,4881
@@ -11,15 +11,15 @@ enkryptai_sdk/models.py,sha256=3y6-7vaDrEmDZpc3zHmIsBs7DFjDprf_EA7PU2yPU0c,8976
11
11
  enkryptai_sdk/red_team.py,sha256=DbJRpWwZBHljR3o247PvqCzJm3_TV9UXaxISeUmEJ5w,14188
12
12
  enkryptai_sdk/response.py,sha256=43JRubzgGCpoVxYNzBZY0AlUgLbfcXD_AwD7wU3qY9o,4086
13
13
  enkryptai_sdk/dto/__init__.py,sha256=kKBw4rkfqMBuK8nXRDtD6Sd0_uqLKgbcHrqzuSGJpr0,2310
14
- enkryptai_sdk/dto/ai_proxy.py,sha256=1Y5B0O3ooS4PNnvDkzf4e0zGyr8HoWeN5am3fg5sjrA,11024
14
+ enkryptai_sdk/dto/ai_proxy.py,sha256=clwMN4xdH8Zr55dnhilHbs-qaHRlCOrLPrij0Zd1Av0,11283
15
15
  enkryptai_sdk/dto/base.py,sha256=6VWTkoNZ7uILqn_iYsPS21cVa2xLYpw5bjDIsRCS5tk,2389
16
16
  enkryptai_sdk/dto/datasets.py,sha256=E3hvHvGZ94iMvCslTcYM3VCKszVQq_xtu93nlm4dZhI,4444
17
17
  enkryptai_sdk/dto/deployments.py,sha256=lsKdG09C-rceIjGvEyYOBf5zBjrk7ma8NpPfgrAgdfM,10829
18
18
  enkryptai_sdk/dto/guardrails.py,sha256=XMFco-KlEqI4TYoJAyxxTrk-OFixtEcftBpG1SXFH4k,39583
19
19
  enkryptai_sdk/dto/models.py,sha256=O4gVhVTenlsytNJIvk2gO5530KZWMye6FCVCtF5IW-A,11700
20
20
  enkryptai_sdk/dto/red_team.py,sha256=BoOPYFjIONIC0XPuyJtkx_qLVYi2kLGEA4CzlySgbJA,13829
21
- enkryptai_sdk-1.0.1.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- enkryptai_sdk-1.0.1.dist-info/METADATA,sha256=jwRXWQw3EbYvzN3lmiPUcua-5m1dqPNT-Wi4uvllYEk,43106
23
- enkryptai_sdk-1.0.1.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
24
- enkryptai_sdk-1.0.1.dist-info/top_level.txt,sha256=s2X9UJJwvJamNmr6ZXWyyQe60sXtQGWFuaBYfhgHI_4,14
25
- enkryptai_sdk-1.0.1.dist-info/RECORD,,
21
+ enkryptai_sdk-1.0.2.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ enkryptai_sdk-1.0.2.dist-info/METADATA,sha256=erxYdcKCSpIFnjCvMQWFRETJk8xa7ErFuMlqv9dPA6I,43207
23
+ enkryptai_sdk-1.0.2.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
24
+ enkryptai_sdk-1.0.2.dist-info/top_level.txt,sha256=s2X9UJJwvJamNmr6ZXWyyQe60sXtQGWFuaBYfhgHI_4,14
25
+ enkryptai_sdk-1.0.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (77.0.3)
2
+ Generator: setuptools (78.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5