pangea-sdk 5.4.0b2__tar.gz → 5.5.0b1__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.
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/PKG-INFO +13 -13
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/README.md +2 -2
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/__init__.py +1 -1
- pangea_sdk-5.5.0b1/pangea/asyncio/services/ai_guard.py +156 -0
- pangea_sdk-5.5.0b1/pangea/services/ai_guard.py +209 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pyproject.toml +11 -23
- pangea_sdk-5.4.0b2/pangea/asyncio/services/ai_guard.py +0 -75
- pangea_sdk-5.4.0b2/pangea/services/ai_guard.py +0 -128
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/__init__.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/file_uploader.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/request.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/services/__init__.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/services/audit.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/services/authn.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/services/authz.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/services/base.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/services/embargo.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/services/file_scan.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/services/intel.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/services/prompt_guard.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/services/redact.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/services/sanitize.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/services/share.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/asyncio/services/vault.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/audit_logger.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/config.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/crypto/rsa.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/deep_verify.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/deprecated.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/dump_audit.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/exceptions.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/file_uploader.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/py.typed +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/request.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/response.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/__init__.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/audit/audit.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/audit/exceptions.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/audit/models.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/audit/signing.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/audit/util.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/authn/authn.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/authn/models.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/authz.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/base.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/embargo.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/file_scan.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/intel.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/prompt_guard.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/redact.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/sanitize.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/share/file_format.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/share/share.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/vault/models/asymmetric.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/vault/models/common.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/vault/models/keys.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/vault/models/secret.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/vault/models/symmetric.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/services/vault/vault.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/tools.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/utils.py +0 -0
- {pangea_sdk-5.4.0b2 → pangea_sdk-5.5.0b1}/pangea/verify_audit.py +0 -0
@@ -1,23 +1,23 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: pangea-sdk
|
3
|
-
Version: 5.
|
3
|
+
Version: 5.5.0b1
|
4
4
|
Summary: Pangea API SDK
|
5
5
|
License: MIT
|
6
6
|
Keywords: Pangea,SDK,Audit
|
7
7
|
Author: Glenn Gallien
|
8
8
|
Author-email: glenn.gallien@pangea.cloud
|
9
|
-
Requires-Python: >=3.9
|
9
|
+
Requires-Python: >=3.9,<4.0.0
|
10
10
|
Classifier: Topic :: Software Development
|
11
11
|
Classifier: Topic :: Software Development :: Libraries
|
12
|
-
Requires-Dist: aiohttp
|
13
|
-
Requires-Dist: cryptography
|
14
|
-
Requires-Dist: deprecated
|
15
|
-
Requires-Dist: google-crc32c
|
16
|
-
Requires-Dist: pydantic
|
17
|
-
Requires-Dist: python-dateutil
|
18
|
-
Requires-Dist: requests
|
19
|
-
Requires-Dist: requests-toolbelt
|
20
|
-
Requires-Dist: typing-extensions
|
12
|
+
Requires-Dist: aiohttp (>=3.11.11,<4.0.0)
|
13
|
+
Requires-Dist: cryptography (>=43.0.3,<44.0.0)
|
14
|
+
Requires-Dist: deprecated (>=1.2.15,<2.0.0)
|
15
|
+
Requires-Dist: google-crc32c (>=1.5.0,<2.0.0)
|
16
|
+
Requires-Dist: pydantic (>=2.10.5,<3.0.0)
|
17
|
+
Requires-Dist: python-dateutil (>=2.9.0,<3.0.0)
|
18
|
+
Requires-Dist: requests (>=2.31.0,<3.0.0)
|
19
|
+
Requires-Dist: requests-toolbelt (>=1.0.0,<2.0.0)
|
20
|
+
Requires-Dist: typing-extensions (>=4.12.2,<5.0.0)
|
21
21
|
Description-Content-Type: text/markdown
|
22
22
|
|
23
23
|
<a href="https://pangea.cloud?utm_source=github&utm_medium=python-sdk" target="_blank" rel="noopener noreferrer">
|
@@ -63,13 +63,13 @@ the same compatibility guarantees as stable releases.
|
|
63
63
|
Via pip:
|
64
64
|
|
65
65
|
```bash
|
66
|
-
$ pip3 install pangea-sdk==5.
|
66
|
+
$ pip3 install pangea-sdk==5.5.0b1
|
67
67
|
```
|
68
68
|
|
69
69
|
Via poetry:
|
70
70
|
|
71
71
|
```bash
|
72
|
-
$ poetry add pangea-sdk==5.
|
72
|
+
$ poetry add pangea-sdk==5.5.0b1
|
73
73
|
```
|
74
74
|
|
75
75
|
## Usage
|
@@ -41,13 +41,13 @@ the same compatibility guarantees as stable releases.
|
|
41
41
|
Via pip:
|
42
42
|
|
43
43
|
```bash
|
44
|
-
$ pip3 install pangea-sdk==5.
|
44
|
+
$ pip3 install pangea-sdk==5.5.0b1
|
45
45
|
```
|
46
46
|
|
47
47
|
Via poetry:
|
48
48
|
|
49
49
|
```bash
|
50
|
-
$ poetry add pangea-sdk==5.
|
50
|
+
$ poetry add pangea-sdk==5.5.0b1
|
51
51
|
```
|
52
52
|
|
53
53
|
## Usage
|
@@ -0,0 +1,156 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from typing import overload
|
4
|
+
|
5
|
+
from typing_extensions import TypeVar
|
6
|
+
|
7
|
+
from pangea.asyncio.services.base import ServiceBaseAsync
|
8
|
+
from pangea.config import PangeaConfig
|
9
|
+
from pangea.response import PangeaResponse
|
10
|
+
from pangea.services.ai_guard import TextGuardResult
|
11
|
+
|
12
|
+
_T = TypeVar("_T")
|
13
|
+
|
14
|
+
|
15
|
+
class AIGuardAsync(ServiceBaseAsync):
|
16
|
+
"""AI Guard service client.
|
17
|
+
|
18
|
+
Provides methods to interact with Pangea's AI Guard service.
|
19
|
+
|
20
|
+
Examples:
|
21
|
+
from pangea import PangeaConfig
|
22
|
+
from pangea.asyncio.services import AIGuardAsync
|
23
|
+
|
24
|
+
config = PangeaConfig(domain="aws.us.pangea.cloud")
|
25
|
+
ai_guard = AIGuardAsync(token="pangea_token", config=config)
|
26
|
+
"""
|
27
|
+
|
28
|
+
service_name = "ai-guard"
|
29
|
+
|
30
|
+
def __init__(
|
31
|
+
self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
|
32
|
+
) -> None:
|
33
|
+
"""
|
34
|
+
AI Guard service client.
|
35
|
+
|
36
|
+
Initializes a new AI Guard client.
|
37
|
+
|
38
|
+
Args:
|
39
|
+
token: Pangea API token.
|
40
|
+
config: Pangea service configuration.
|
41
|
+
logger_name: Logger name.
|
42
|
+
config_id: Configuration ID.
|
43
|
+
|
44
|
+
Examples:
|
45
|
+
from pangea import PangeaConfig
|
46
|
+
from pangea.asyncio.services import AIGuardAsync
|
47
|
+
|
48
|
+
config = PangeaConfig(domain="aws.us.pangea.cloud")
|
49
|
+
ai_guard = AIGuardAsync(token="pangea_token", config=config)
|
50
|
+
"""
|
51
|
+
|
52
|
+
super().__init__(token, config, logger_name, config_id)
|
53
|
+
|
54
|
+
@overload
|
55
|
+
async def guard_text(
|
56
|
+
self,
|
57
|
+
text_or_messages: str,
|
58
|
+
*,
|
59
|
+
recipe: str = "pangea_prompt_guard",
|
60
|
+
debug: bool = False,
|
61
|
+
) -> PangeaResponse[TextGuardResult[None]]:
|
62
|
+
"""
|
63
|
+
Text Guard for scanning LLM inputs and outputs (Beta)
|
64
|
+
|
65
|
+
Analyze and redact text to avoid manipulation of the model, addition of
|
66
|
+
malicious content, and other undesirable data transfers.
|
67
|
+
|
68
|
+
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
69
|
+
|
70
|
+
OperationId: ai_guard_post_v1beta_text_guard
|
71
|
+
|
72
|
+
Args:
|
73
|
+
text: Text to be scanned by AI Guard for PII, sensitive data,
|
74
|
+
malicious content, and other data types defined by the
|
75
|
+
configuration. Supports processing up to 10KB of text.
|
76
|
+
recipe: Recipe key of a configuration of data types and settings
|
77
|
+
defined in the Pangea User Console. It specifies the rules that
|
78
|
+
are to be applied to the text, such as defang malicious URLs.
|
79
|
+
debug: Setting this value to true will provide a detailed analysis
|
80
|
+
of the text data
|
81
|
+
|
82
|
+
Examples:
|
83
|
+
response = await ai_guard.guard_text("text")
|
84
|
+
"""
|
85
|
+
|
86
|
+
@overload
|
87
|
+
async def guard_text(
|
88
|
+
self,
|
89
|
+
text_or_messages: _T,
|
90
|
+
*,
|
91
|
+
recipe: str = "pangea_prompt_guard",
|
92
|
+
debug: bool = False,
|
93
|
+
) -> PangeaResponse[TextGuardResult[_T]]:
|
94
|
+
"""
|
95
|
+
Text Guard for scanning LLM inputs and outputs (Beta)
|
96
|
+
|
97
|
+
Analyze and redact text to avoid manipulation of the model, addition of
|
98
|
+
malicious content, and other undesirable data transfers.
|
99
|
+
|
100
|
+
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
101
|
+
|
102
|
+
OperationId: ai_guard_post_v1beta_text_guard
|
103
|
+
|
104
|
+
Args:
|
105
|
+
text_or_messages: Structured data to be scanned by AI Guard for PII,
|
106
|
+
sensitive data, malicious content, and other data types defined
|
107
|
+
by the configuration. Supports processing up to 10KB of text.
|
108
|
+
recipe: Recipe key of a configuration of data types and settings
|
109
|
+
defined in the Pangea User Console. It specifies the rules that
|
110
|
+
are to be applied to the text, such as defang malicious URLs.
|
111
|
+
debug: Setting this value to true will provide a detailed analysis
|
112
|
+
of the text data
|
113
|
+
|
114
|
+
Examples:
|
115
|
+
response = await ai_guard.guard_text([
|
116
|
+
{"role": "user", "content": "hello world"}
|
117
|
+
])
|
118
|
+
"""
|
119
|
+
|
120
|
+
async def guard_text(
|
121
|
+
self,
|
122
|
+
text_or_messages: str | _T,
|
123
|
+
*,
|
124
|
+
recipe: str = "pangea_prompt_guard",
|
125
|
+
debug: bool = False,
|
126
|
+
) -> PangeaResponse[TextGuardResult[_T]]:
|
127
|
+
"""
|
128
|
+
Text Guard for scanning LLM inputs and outputs (Beta)
|
129
|
+
|
130
|
+
Analyze and redact text to avoid manipulation of the model, addition of
|
131
|
+
malicious content, and other undesirable data transfers.
|
132
|
+
|
133
|
+
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
134
|
+
|
135
|
+
OperationId: ai_guard_post_v1beta_text_guard
|
136
|
+
|
137
|
+
Args:
|
138
|
+
text_or_messages: Text or structured data to be scanned by AI Guard
|
139
|
+
for PII, sensitive data, malicious content, and other data types
|
140
|
+
defined by the configuration. Supports processing up to 10KB of text.
|
141
|
+
recipe: Recipe key of a configuration of data types and settings
|
142
|
+
defined in the Pangea User Console. It specifies the rules that
|
143
|
+
are to be applied to the text, such as defang malicious URLs.
|
144
|
+
debug: Setting this value to true will provide a detailed analysis
|
145
|
+
of the text data
|
146
|
+
"""
|
147
|
+
|
148
|
+
return await self.request.post(
|
149
|
+
"v1beta/text/guard",
|
150
|
+
TextGuardResult,
|
151
|
+
data={
|
152
|
+
"text" if isinstance(text_or_messages, str) else "messages": text_or_messages,
|
153
|
+
"recipe": recipe,
|
154
|
+
"debug": debug,
|
155
|
+
},
|
156
|
+
)
|
@@ -0,0 +1,209 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from typing import Any, Dict, Generic, List, Optional, TypeVar, overload
|
4
|
+
|
5
|
+
from pangea.config import PangeaConfig
|
6
|
+
from pangea.response import APIResponseModel, PangeaResponse, PangeaResponseResult
|
7
|
+
from pangea.services.base import ServiceBase
|
8
|
+
|
9
|
+
|
10
|
+
class AnalyzerResponse(APIResponseModel):
|
11
|
+
analyzer: str
|
12
|
+
confidence: float
|
13
|
+
|
14
|
+
|
15
|
+
class PromptInjectionResult(APIResponseModel):
|
16
|
+
analyzer_responses: List[AnalyzerResponse]
|
17
|
+
"""Triggered prompt injection analyzers."""
|
18
|
+
|
19
|
+
|
20
|
+
class PiiEntity(APIResponseModel):
|
21
|
+
type: str
|
22
|
+
value: str
|
23
|
+
redacted: bool
|
24
|
+
start_pos: Optional[int] = None
|
25
|
+
|
26
|
+
|
27
|
+
class PiiEntityResult(APIResponseModel):
|
28
|
+
entities: List[PiiEntity]
|
29
|
+
|
30
|
+
|
31
|
+
class MaliciousEntity(APIResponseModel):
|
32
|
+
type: str
|
33
|
+
value: str
|
34
|
+
redacted: Optional[bool] = None
|
35
|
+
start_pos: Optional[int] = None
|
36
|
+
raw: Optional[Dict[str, Any]] = None
|
37
|
+
|
38
|
+
|
39
|
+
class MaliciousEntityResult(APIResponseModel):
|
40
|
+
entities: List[MaliciousEntity]
|
41
|
+
|
42
|
+
|
43
|
+
_T = TypeVar("_T")
|
44
|
+
|
45
|
+
|
46
|
+
class TextGuardDetector(APIResponseModel, Generic[_T]):
|
47
|
+
detected: bool
|
48
|
+
data: Optional[_T] = None
|
49
|
+
|
50
|
+
|
51
|
+
class TextGuardDetectors(APIResponseModel):
|
52
|
+
prompt_injection: Optional[TextGuardDetector[PromptInjectionResult]] = None
|
53
|
+
pii_entity: Optional[TextGuardDetector[PiiEntityResult]] = None
|
54
|
+
malicious_entity: Optional[TextGuardDetector[MaliciousEntityResult]] = None
|
55
|
+
|
56
|
+
|
57
|
+
class TextGuardResult(PangeaResponseResult, Generic[_T]):
|
58
|
+
detectors: TextGuardDetectors
|
59
|
+
"""Result of the recipe analyzing and input prompt."""
|
60
|
+
|
61
|
+
prompt_text: Optional[str] = None
|
62
|
+
"""Updated prompt text, if applicable."""
|
63
|
+
|
64
|
+
prompt_messages: Optional[_T] = None
|
65
|
+
"""Updated structured prompt, if applicable."""
|
66
|
+
|
67
|
+
|
68
|
+
class AIGuard(ServiceBase):
|
69
|
+
"""AI Guard service client.
|
70
|
+
|
71
|
+
Provides methods to interact with Pangea's AI Guard service.
|
72
|
+
|
73
|
+
Examples:
|
74
|
+
from pangea import PangeaConfig
|
75
|
+
from pangea.services import AIGuard
|
76
|
+
|
77
|
+
config = PangeaConfig(domain="aws.us.pangea.cloud")
|
78
|
+
ai_guard = AIGuard(token="pangea_token", config=config)
|
79
|
+
"""
|
80
|
+
|
81
|
+
service_name = "ai-guard"
|
82
|
+
|
83
|
+
def __init__(
|
84
|
+
self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
|
85
|
+
) -> None:
|
86
|
+
"""
|
87
|
+
AI Guard service client.
|
88
|
+
|
89
|
+
Initializes a new AI Guard client.
|
90
|
+
|
91
|
+
Args:
|
92
|
+
token: Pangea API token.
|
93
|
+
config: Pangea service configuration.
|
94
|
+
logger_name: Logger name.
|
95
|
+
config_id: Configuration ID.
|
96
|
+
|
97
|
+
Examples:
|
98
|
+
from pangea import PangeaConfig
|
99
|
+
from pangea.services import AIGuard
|
100
|
+
|
101
|
+
config = PangeaConfig(domain="aws.us.pangea.cloud")
|
102
|
+
ai_guard = AIGuard(token="pangea_token", config=config)
|
103
|
+
"""
|
104
|
+
|
105
|
+
super().__init__(token, config, logger_name, config_id)
|
106
|
+
|
107
|
+
@overload
|
108
|
+
def guard_text(
|
109
|
+
self,
|
110
|
+
text_or_messages: str,
|
111
|
+
*,
|
112
|
+
recipe: str = "pangea_prompt_guard",
|
113
|
+
debug: bool = False,
|
114
|
+
) -> PangeaResponse[TextGuardResult[None]]:
|
115
|
+
"""
|
116
|
+
Text Guard for scanning LLM inputs and outputs (Beta)
|
117
|
+
|
118
|
+
Analyze and redact text to avoid manipulation of the model, addition of
|
119
|
+
malicious content, and other undesirable data transfers.
|
120
|
+
|
121
|
+
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
122
|
+
|
123
|
+
OperationId: ai_guard_post_v1beta_text_guard
|
124
|
+
|
125
|
+
Args:
|
126
|
+
text: Text to be scanned by AI Guard for PII, sensitive data,
|
127
|
+
malicious content, and other data types defined by the
|
128
|
+
configuration. Supports processing up to 10KB of text.
|
129
|
+
recipe: Recipe key of a configuration of data types and settings
|
130
|
+
defined in the Pangea User Console. It specifies the rules that
|
131
|
+
are to be applied to the text, such as defang malicious URLs.
|
132
|
+
debug: Setting this value to true will provide a detailed analysis
|
133
|
+
of the text data
|
134
|
+
|
135
|
+
Examples:
|
136
|
+
response = ai_guard.guard_text("text")
|
137
|
+
"""
|
138
|
+
|
139
|
+
@overload
|
140
|
+
def guard_text(
|
141
|
+
self,
|
142
|
+
text_or_messages: _T,
|
143
|
+
*,
|
144
|
+
recipe: str = "pangea_prompt_guard",
|
145
|
+
debug: bool = False,
|
146
|
+
) -> PangeaResponse[TextGuardResult[_T]]:
|
147
|
+
"""
|
148
|
+
Text Guard for scanning LLM inputs and outputs (Beta)
|
149
|
+
|
150
|
+
Analyze and redact text to avoid manipulation of the model, addition of
|
151
|
+
malicious content, and other undesirable data transfers.
|
152
|
+
|
153
|
+
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
154
|
+
|
155
|
+
OperationId: ai_guard_post_v1beta_text_guard
|
156
|
+
|
157
|
+
Args:
|
158
|
+
text_or_messages: Structured data to be scanned by AI Guard for PII,
|
159
|
+
sensitive data, malicious content, and other data types defined
|
160
|
+
by the configuration. Supports processing up to 10KB of text.
|
161
|
+
recipe: Recipe key of a configuration of data types and settings
|
162
|
+
defined in the Pangea User Console. It specifies the rules that
|
163
|
+
are to be applied to the text, such as defang malicious URLs.
|
164
|
+
debug: Setting this value to true will provide a detailed analysis
|
165
|
+
of the text data
|
166
|
+
|
167
|
+
Examples:
|
168
|
+
response = ai_guard.guard_text([
|
169
|
+
{"role": "user", "content": "hello world"}
|
170
|
+
])
|
171
|
+
"""
|
172
|
+
|
173
|
+
def guard_text(
|
174
|
+
self,
|
175
|
+
text_or_messages: str | _T,
|
176
|
+
*,
|
177
|
+
recipe: str = "pangea_prompt_guard",
|
178
|
+
debug: bool = False,
|
179
|
+
) -> PangeaResponse[TextGuardResult[_T]]:
|
180
|
+
"""
|
181
|
+
Text Guard for scanning LLM inputs and outputs (Beta)
|
182
|
+
|
183
|
+
Analyze and redact text to avoid manipulation of the model, addition of
|
184
|
+
malicious content, and other undesirable data transfers.
|
185
|
+
|
186
|
+
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
187
|
+
|
188
|
+
OperationId: ai_guard_post_v1beta_text_guard
|
189
|
+
|
190
|
+
Args:
|
191
|
+
text_or_messages: Text or structured data to be scanned by AI Guard
|
192
|
+
for PII, sensitive data, malicious content, and other data types
|
193
|
+
defined by the configuration. Supports processing up to 10KB of text.
|
194
|
+
recipe: Recipe key of a configuration of data types and settings
|
195
|
+
defined in the Pangea User Console. It specifies the rules that
|
196
|
+
are to be applied to the text, such as defang malicious URLs.
|
197
|
+
debug: Setting this value to true will provide a detailed analysis
|
198
|
+
of the text data
|
199
|
+
"""
|
200
|
+
|
201
|
+
return self.request.post(
|
202
|
+
"v1beta/text/guard",
|
203
|
+
TextGuardResult,
|
204
|
+
data={
|
205
|
+
"text" if isinstance(text_or_messages, str) else "messages": text_or_messages,
|
206
|
+
"recipe": recipe,
|
207
|
+
"debug": debug,
|
208
|
+
},
|
209
|
+
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "pangea-sdk"
|
3
|
-
version = "5.
|
3
|
+
version = "5.5.0beta1"
|
4
4
|
description = "Pangea API SDK"
|
5
5
|
authors = [
|
6
6
|
{name = "Glenn Gallien", email = "glenn.gallien@pangea.cloud"}
|
@@ -14,17 +14,17 @@ classifiers = [
|
|
14
14
|
"Topic :: Software Development",
|
15
15
|
"Topic :: Software Development :: Libraries",
|
16
16
|
]
|
17
|
-
requires-python = ">=3.9"
|
17
|
+
requires-python = ">=3.9,<4.0.0"
|
18
18
|
dependencies = [
|
19
|
-
"aiohttp",
|
20
|
-
"cryptography",
|
21
|
-
"deprecated",
|
22
|
-
"google-crc32c",
|
23
|
-
"pydantic",
|
24
|
-
"python-dateutil",
|
25
|
-
"requests
|
26
|
-
"requests",
|
27
|
-
"typing-extensions"
|
19
|
+
"aiohttp (>=3.11.11,<4.0.0)",
|
20
|
+
"cryptography (>=43.0.3,<44.0.0)",
|
21
|
+
"deprecated (>=1.2.15,<2.0.0)",
|
22
|
+
"google-crc32c (>=1.5.0,<2.0.0)",
|
23
|
+
"pydantic (>=2.10.5,<3.0.0)",
|
24
|
+
"python-dateutil (>=2.9.0,<3.0.0)",
|
25
|
+
"requests (>=2.31.0,<3.0.0)",
|
26
|
+
"requests-toolbelt (>=1.0.0,<2.0.0)",
|
27
|
+
"typing-extensions (>=4.12.2,<5.0.0)"
|
28
28
|
]
|
29
29
|
|
30
30
|
[tool.poetry]
|
@@ -32,18 +32,6 @@ packages = [
|
|
32
32
|
{ include = "pangea" }
|
33
33
|
]
|
34
34
|
|
35
|
-
[tool.poetry.dependencies]
|
36
|
-
python = "^3.9.0"
|
37
|
-
aiohttp = "^3.11.11"
|
38
|
-
cryptography = "^43.0.3"
|
39
|
-
deprecated = "^1.2.15"
|
40
|
-
google-crc32c = "^1.5.0"
|
41
|
-
pydantic = "^2.10.5"
|
42
|
-
python-dateutil = "^2.9.0"
|
43
|
-
requests = "^2.31.0"
|
44
|
-
requests-toolbelt = "^1.0.0"
|
45
|
-
typing-extensions = "^4.12.2"
|
46
|
-
|
47
35
|
[tool.poetry.group.dev.dependencies]
|
48
36
|
black = "^24.10.0"
|
49
37
|
docstring-parser = "^0.15"
|
@@ -1,75 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
from pangea.asyncio.services.base import ServiceBaseAsync
|
4
|
-
from pangea.config import PangeaConfig
|
5
|
-
from pangea.response import PangeaResponse
|
6
|
-
from pangea.services.ai_guard import TextGuardResult
|
7
|
-
|
8
|
-
|
9
|
-
class AIGuardAsync(ServiceBaseAsync):
|
10
|
-
"""AI Guard service client.
|
11
|
-
|
12
|
-
Provides methods to interact with Pangea's AI Guard service.
|
13
|
-
|
14
|
-
Examples:
|
15
|
-
from pangea import PangeaConfig
|
16
|
-
from pangea.asyncio.services import AIGuardAsync
|
17
|
-
|
18
|
-
config = PangeaConfig(domain="aws.us.pangea.cloud")
|
19
|
-
ai_guard = AIGuardAsync(token="pangea_token", config=config)
|
20
|
-
"""
|
21
|
-
|
22
|
-
service_name = "ai-guard"
|
23
|
-
|
24
|
-
def __init__(
|
25
|
-
self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
|
26
|
-
) -> None:
|
27
|
-
"""
|
28
|
-
AI Guard service client.
|
29
|
-
|
30
|
-
Initializes a new AI Guard client.
|
31
|
-
|
32
|
-
Args:
|
33
|
-
token: Pangea API token.
|
34
|
-
config: Pangea service configuration.
|
35
|
-
logger_name: Logger name.
|
36
|
-
config_id: Configuration ID.
|
37
|
-
|
38
|
-
Examples:
|
39
|
-
from pangea import PangeaConfig
|
40
|
-
from pangea.asyncio.services import AIGuardAsync
|
41
|
-
|
42
|
-
config = PangeaConfig(domain="aws.us.pangea.cloud")
|
43
|
-
ai_guard = AIGuardAsync(token="pangea_token", config=config)
|
44
|
-
"""
|
45
|
-
|
46
|
-
super().__init__(token, config, logger_name, config_id)
|
47
|
-
|
48
|
-
async def guard_text(
|
49
|
-
self,
|
50
|
-
text: str,
|
51
|
-
*,
|
52
|
-
recipe: str = "pangea_prompt_guard",
|
53
|
-
debug: bool = False,
|
54
|
-
) -> PangeaResponse[TextGuardResult]:
|
55
|
-
"""
|
56
|
-
Text guard (Beta)
|
57
|
-
|
58
|
-
Guard text.
|
59
|
-
|
60
|
-
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
61
|
-
|
62
|
-
OperationId: ai_guard_post_v1beta_text_guard
|
63
|
-
|
64
|
-
Args:
|
65
|
-
text: Text.
|
66
|
-
recipe: Recipe.
|
67
|
-
debug: Debug.
|
68
|
-
|
69
|
-
Examples:
|
70
|
-
response = await ai_guard.guard_text("text")
|
71
|
-
"""
|
72
|
-
|
73
|
-
return await self.request.post(
|
74
|
-
"v1beta/text/guard", TextGuardResult, data={"text": text, "recipe": recipe, "debug": debug}
|
75
|
-
)
|
@@ -1,128 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
from typing import Any, Dict, Generic, List, Optional, TypeVar
|
4
|
-
|
5
|
-
from pangea.config import PangeaConfig
|
6
|
-
from pangea.response import APIResponseModel, PangeaResponse, PangeaResponseResult
|
7
|
-
from pangea.services.base import ServiceBase
|
8
|
-
|
9
|
-
|
10
|
-
class AnalyzerResponse(APIResponseModel):
|
11
|
-
analyzer: str
|
12
|
-
confidence: float
|
13
|
-
|
14
|
-
|
15
|
-
class PromptInjectionResult(APIResponseModel):
|
16
|
-
analyzer_responses: List[AnalyzerResponse]
|
17
|
-
"""Triggered prompt injection analyzers."""
|
18
|
-
|
19
|
-
|
20
|
-
class PiiEntity(APIResponseModel):
|
21
|
-
type: str
|
22
|
-
value: str
|
23
|
-
redacted: bool
|
24
|
-
start_pos: Optional[int] = None
|
25
|
-
|
26
|
-
|
27
|
-
class PiiEntityResult(APIResponseModel):
|
28
|
-
entities: List[PiiEntity]
|
29
|
-
|
30
|
-
|
31
|
-
class MaliciousEntity(APIResponseModel):
|
32
|
-
type: str
|
33
|
-
value: str
|
34
|
-
redacted: Optional[bool] = None
|
35
|
-
start_pos: Optional[int] = None
|
36
|
-
raw: Optional[Dict[str, Any]] = None
|
37
|
-
|
38
|
-
|
39
|
-
class MaliciousEntityResult(APIResponseModel):
|
40
|
-
entities: List[MaliciousEntity]
|
41
|
-
|
42
|
-
|
43
|
-
T = TypeVar("T")
|
44
|
-
|
45
|
-
|
46
|
-
class TextGuardDetector(APIResponseModel, Generic[T]):
|
47
|
-
detected: bool
|
48
|
-
data: Optional[T] = None
|
49
|
-
|
50
|
-
|
51
|
-
class TextGuardDetectors(APIResponseModel):
|
52
|
-
prompt_injection: Optional[TextGuardDetector[PromptInjectionResult]] = None
|
53
|
-
pii_entity: Optional[TextGuardDetector[PiiEntityResult]] = None
|
54
|
-
malicious_entity: Optional[TextGuardDetector[MaliciousEntityResult]] = None
|
55
|
-
|
56
|
-
|
57
|
-
class TextGuardResult(PangeaResponseResult):
|
58
|
-
detectors: TextGuardDetectors
|
59
|
-
prompt: str
|
60
|
-
|
61
|
-
|
62
|
-
class AIGuard(ServiceBase):
|
63
|
-
"""AI Guard service client.
|
64
|
-
|
65
|
-
Provides methods to interact with Pangea's AI Guard service.
|
66
|
-
|
67
|
-
Examples:
|
68
|
-
from pangea import PangeaConfig
|
69
|
-
from pangea.services import AIGuard
|
70
|
-
|
71
|
-
config = PangeaConfig(domain="aws.us.pangea.cloud")
|
72
|
-
ai_guard = AIGuard(token="pangea_token", config=config)
|
73
|
-
"""
|
74
|
-
|
75
|
-
service_name = "ai-guard"
|
76
|
-
|
77
|
-
def __init__(
|
78
|
-
self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
|
79
|
-
) -> None:
|
80
|
-
"""
|
81
|
-
AI Guard service client.
|
82
|
-
|
83
|
-
Initializes a new AI Guard client.
|
84
|
-
|
85
|
-
Args:
|
86
|
-
token: Pangea API token.
|
87
|
-
config: Pangea service configuration.
|
88
|
-
logger_name: Logger name.
|
89
|
-
config_id: Configuration ID.
|
90
|
-
|
91
|
-
Examples:
|
92
|
-
from pangea import PangeaConfig
|
93
|
-
from pangea.services import AIGuard
|
94
|
-
|
95
|
-
config = PangeaConfig(domain="aws.us.pangea.cloud")
|
96
|
-
ai_guard = AIGuard(token="pangea_token", config=config)
|
97
|
-
"""
|
98
|
-
|
99
|
-
super().__init__(token, config, logger_name, config_id)
|
100
|
-
|
101
|
-
def guard_text(
|
102
|
-
self,
|
103
|
-
text: str,
|
104
|
-
*,
|
105
|
-
recipe: str = "pangea_prompt_guard",
|
106
|
-
debug: bool = False,
|
107
|
-
) -> PangeaResponse[TextGuardResult]:
|
108
|
-
"""
|
109
|
-
Text guard (Beta)
|
110
|
-
|
111
|
-
Guard text.
|
112
|
-
|
113
|
-
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
114
|
-
|
115
|
-
OperationId: ai_guard_post_v1beta_text_guard
|
116
|
-
|
117
|
-
Args:
|
118
|
-
text: Text.
|
119
|
-
recipe: Recipe.
|
120
|
-
debug: Debug.
|
121
|
-
|
122
|
-
Examples:
|
123
|
-
response = ai_guard.guard_text("text")
|
124
|
-
"""
|
125
|
-
|
126
|
-
return self.request.post(
|
127
|
-
"v1beta/text/guard", TextGuardResult, data={"text": text, "recipe": recipe, "debug": debug}
|
128
|
-
)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|