enkryptai-sdk 1.0.1__tar.gz → 1.0.3__tar.gz

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.
Files changed (41) hide show
  1. {enkryptai_sdk-1.0.1/src/enkryptai_sdk.egg-info → enkryptai_sdk-1.0.3}/PKG-INFO +2 -1
  2. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/README.md +1 -0
  3. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/setup.py +1 -1
  4. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/ai_proxy.py +25 -6
  5. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/dto/ai_proxy.py +5 -2
  6. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3/src/enkryptai_sdk.egg-info}/PKG-INFO +2 -1
  7. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/tests/test_all.py +3 -0
  8. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/tests/test_datasets.py +1 -0
  9. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/tests/test_redteam.py +2 -0
  10. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/LICENSE +0 -0
  11. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/setup.cfg +0 -0
  12. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/__init__.py +0 -0
  13. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/base.py +0 -0
  14. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/config.py +0 -0
  15. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/datasets.py +0 -0
  16. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/deployments.py +0 -0
  17. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/dto/__init__.py +0 -0
  18. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/dto/base.py +0 -0
  19. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/dto/datasets.py +0 -0
  20. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/dto/deployments.py +0 -0
  21. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/dto/guardrails.py +0 -0
  22. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/dto/models.py +0 -0
  23. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/dto/red_team.py +0 -0
  24. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/evals.py +0 -0
  25. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/guardrails.py +0 -0
  26. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/guardrails_old.py +0 -0
  27. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/models.py +0 -0
  28. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/red_team.py +0 -0
  29. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk/response.py +0 -0
  30. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk.egg-info/SOURCES.txt +0 -0
  31. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk.egg-info/dependency_links.txt +0 -0
  32. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/src/enkryptai_sdk.egg-info/top_level.txt +0 -0
  33. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/tests/test_ai_proxy.py +0 -0
  34. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/tests/test_basic.py +0 -0
  35. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/tests/test_deployments.py +0 -0
  36. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/tests/test_detect_policy.py +0 -0
  37. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/tests/test_guardrails.py +0 -0
  38. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/tests/test_injection_attack.py +0 -0
  39. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/tests/test_model.py +0 -0
  40. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/tests/test_openai.py +0 -0
  41. {enkryptai_sdk-1.0.1 → enkryptai_sdk-1.0.3}/tests/test_policy_violation.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: enkryptai-sdk
3
- Version: 1.0.1
3
+ Version: 1.0.3
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,3 +1,4 @@
1
+ ![Python SDK test](https://github.com/enkryptai/enkryptai-sdk/actions/workflows/test.yaml/badge.svg)
1
2
  # Enkrypt AI Python SDK
2
3
 
3
4
  A Python SDK with Guardrails, Models, Deployments, AI Proxy, Datasets and Red Team functionality for API interactions.
@@ -8,7 +8,7 @@ with open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
8
8
 
9
9
  setup(
10
10
  name="enkryptai-sdk", # This is the name of your package on PyPI
11
- version="1.0.1", # Update this for new versions
11
+ version="1.0.3", # Update this for new versions
12
12
  description="A Python SDK with guardrails and red teaming functionality for API interactions",
13
13
  long_description=long_description,
14
14
  long_description_content_type="text/markdown",
@@ -46,24 +46,43 @@ 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:
54
- import json
56
+ import ast
57
+ # import json
55
58
  try:
56
- error_message = json.loads(error_message.replace("'", '"'))
57
- response["error"] = error_message.get("error", error_message)
58
- except json.JSONDecodeError:
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"]
68
+ # except json.JSONDecodeError:
69
+ except Exception:
59
70
  # If parsing fails, keep the original error
60
71
  pass
61
72
 
62
73
  # print("Error in response: ", response)
63
74
  if return_error:
64
- if is_json_str:
75
+ # if is_json_str:
76
+ # return ChatCompletionErrorResponse.from_dict(response)
77
+ # else:
78
+ # return ChatCompletionDirectErrorResponse.from_dict(response)
79
+ try:
80
+ # print("Error in response: ", response)
65
81
  return ChatCompletionErrorResponse.from_dict(response)
66
- else:
82
+ # except (json.JSONDecodeError, TypeError, ValueError, SyntaxError):
83
+ except Exception:
84
+ # Fallback to direct error if error object can't be parsed
85
+ # print("Failed to parse error response: ", response)
67
86
  return ChatCompletionDirectErrorResponse.from_dict(response)
68
87
  raise AIProxyClientError(response["error"])
69
88
 
@@ -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.3
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.
@@ -784,6 +784,7 @@ def test_add_dataset_success(dataset_client, sample_dataset_config):
784
784
  assert hasattr(response, "message")
785
785
  response.message == "Dataset task has been added successfully"
786
786
  # Sleep for a while to let the task complete
787
+ # This is also useful to avoid rate limiting issues
787
788
  import time
788
789
  print("\nSleeping for 60 seconds to let the task complete if possible ...")
789
790
  time.sleep(60)
@@ -926,6 +927,7 @@ def test_add_task_with_target_model(redteam_client, sample_redteam_target_config
926
927
  assert hasattr(response, "message")
927
928
  response.message == "Redteam task has been added successfully"
928
929
  # Sleep for a while to let the task complete
930
+ # This is also useful to avoid rate limiting issues
929
931
  import time
930
932
  print("\nSleeping for 60 seconds to let the task complete if possible ...")
931
933
  time.sleep(60)
@@ -940,6 +942,7 @@ def test_add_task_with_saved_model(redteam_client, sample_redteam_model_config):
940
942
  assert hasattr(response, "message")
941
943
  response.message == "Redteam task has been added successfully"
942
944
  # Sleep for a while to let the task complete
945
+ # This is also useful to avoid rate limiting issues
943
946
  import time
944
947
  print("\nSleeping for 60 seconds to let the task complete if possible ...")
945
948
  time.sleep(60)
@@ -77,6 +77,7 @@ def test_add_dataset_success(dataset_client, sample_dataset_config):
77
77
  assert hasattr(response, "message")
78
78
  response.message == "Dataset task has been added successfully"
79
79
  # Sleep for a while to let the task complete
80
+ # This is also useful to avoid rate limiting issues
80
81
  import time
81
82
  print("\nSleeping for 60 seconds to let the task complete if possible ...")
82
83
  time.sleep(60)
@@ -194,6 +194,7 @@ def test_add_task_with_target_model(redteam_client, sample_redteam_target_config
194
194
  assert hasattr(response, "message")
195
195
  response.message == "Redteam task has been added successfully"
196
196
  # Sleep for a while to let the task complete
197
+ # This is also useful to avoid rate limiting issues
197
198
  import time
198
199
  print("\nSleeping for 60 seconds to let the task complete if possible ...")
199
200
  time.sleep(60)
@@ -208,6 +209,7 @@ def test_add_task_with_saved_model(redteam_client, sample_redteam_model_config):
208
209
  assert hasattr(response, "message")
209
210
  response.message == "Redteam task has been added successfully"
210
211
  # Sleep for a while to let the task complete
212
+ # This is also useful to avoid rate limiting issues
211
213
  import time
212
214
  print("\nSleeping for 60 seconds to let the task complete if possible ...")
213
215
  time.sleep(60)
File without changes
File without changes