pangea-sdk 5.4.0b2__py3-none-any.whl → 5.5.0b1__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.
- pangea/__init__.py +1 -1
- pangea/asyncio/services/ai_guard.py +89 -8
- pangea/services/ai_guard.py +95 -14
- {pangea_sdk-5.4.0b2.dist-info → pangea_sdk-5.5.0b1.dist-info}/METADATA +13 -13
- {pangea_sdk-5.4.0b2.dist-info → pangea_sdk-5.5.0b1.dist-info}/RECORD +6 -6
- {pangea_sdk-5.4.0b2.dist-info → pangea_sdk-5.5.0b1.dist-info}/WHEEL +0 -0
pangea/__init__.py
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
+
from typing import overload
|
4
|
+
|
5
|
+
from typing_extensions import TypeVar
|
6
|
+
|
3
7
|
from pangea.asyncio.services.base import ServiceBaseAsync
|
4
8
|
from pangea.config import PangeaConfig
|
5
9
|
from pangea.response import PangeaResponse
|
6
10
|
from pangea.services.ai_guard import TextGuardResult
|
7
11
|
|
12
|
+
_T = TypeVar("_T")
|
13
|
+
|
8
14
|
|
9
15
|
class AIGuardAsync(ServiceBaseAsync):
|
10
16
|
"""AI Guard service client.
|
@@ -45,31 +51,106 @@ class AIGuardAsync(ServiceBaseAsync):
|
|
45
51
|
|
46
52
|
super().__init__(token, config, logger_name, config_id)
|
47
53
|
|
54
|
+
@overload
|
48
55
|
async def guard_text(
|
49
56
|
self,
|
50
|
-
|
57
|
+
text_or_messages: str,
|
51
58
|
*,
|
52
59
|
recipe: str = "pangea_prompt_guard",
|
53
60
|
debug: bool = False,
|
54
|
-
) -> PangeaResponse[TextGuardResult]:
|
61
|
+
) -> PangeaResponse[TextGuardResult[None]]:
|
55
62
|
"""
|
56
|
-
Text
|
63
|
+
Text Guard for scanning LLM inputs and outputs (Beta)
|
57
64
|
|
58
|
-
|
65
|
+
Analyze and redact text to avoid manipulation of the model, addition of
|
66
|
+
malicious content, and other undesirable data transfers.
|
59
67
|
|
60
68
|
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
61
69
|
|
62
70
|
OperationId: ai_guard_post_v1beta_text_guard
|
63
71
|
|
64
72
|
Args:
|
65
|
-
text: Text
|
66
|
-
|
67
|
-
|
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
|
68
81
|
|
69
82
|
Examples:
|
70
83
|
response = await ai_guard.guard_text("text")
|
71
84
|
"""
|
72
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
|
+
|
73
148
|
return await self.request.post(
|
74
|
-
"v1beta/text/guard",
|
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
|
+
},
|
75
156
|
)
|
pangea/services/ai_guard.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from typing import Any, Dict, Generic, List, Optional, TypeVar
|
3
|
+
from typing import Any, Dict, Generic, List, Optional, TypeVar, overload
|
4
4
|
|
5
5
|
from pangea.config import PangeaConfig
|
6
6
|
from pangea.response import APIResponseModel, PangeaResponse, PangeaResponseResult
|
@@ -40,12 +40,12 @@ class MaliciousEntityResult(APIResponseModel):
|
|
40
40
|
entities: List[MaliciousEntity]
|
41
41
|
|
42
42
|
|
43
|
-
|
43
|
+
_T = TypeVar("_T")
|
44
44
|
|
45
45
|
|
46
|
-
class TextGuardDetector(APIResponseModel, Generic[
|
46
|
+
class TextGuardDetector(APIResponseModel, Generic[_T]):
|
47
47
|
detected: bool
|
48
|
-
data: Optional[
|
48
|
+
data: Optional[_T] = None
|
49
49
|
|
50
50
|
|
51
51
|
class TextGuardDetectors(APIResponseModel):
|
@@ -54,9 +54,15 @@ class TextGuardDetectors(APIResponseModel):
|
|
54
54
|
malicious_entity: Optional[TextGuardDetector[MaliciousEntityResult]] = None
|
55
55
|
|
56
56
|
|
57
|
-
class TextGuardResult(PangeaResponseResult):
|
57
|
+
class TextGuardResult(PangeaResponseResult, Generic[_T]):
|
58
58
|
detectors: TextGuardDetectors
|
59
|
-
prompt
|
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."""
|
60
66
|
|
61
67
|
|
62
68
|
class AIGuard(ServiceBase):
|
@@ -98,31 +104,106 @@ class AIGuard(ServiceBase):
|
|
98
104
|
|
99
105
|
super().__init__(token, config, logger_name, config_id)
|
100
106
|
|
107
|
+
@overload
|
101
108
|
def guard_text(
|
102
109
|
self,
|
103
|
-
|
110
|
+
text_or_messages: str,
|
104
111
|
*,
|
105
112
|
recipe: str = "pangea_prompt_guard",
|
106
113
|
debug: bool = False,
|
107
|
-
) -> PangeaResponse[TextGuardResult]:
|
114
|
+
) -> PangeaResponse[TextGuardResult[None]]:
|
108
115
|
"""
|
109
|
-
Text
|
116
|
+
Text Guard for scanning LLM inputs and outputs (Beta)
|
110
117
|
|
111
|
-
|
118
|
+
Analyze and redact text to avoid manipulation of the model, addition of
|
119
|
+
malicious content, and other undesirable data transfers.
|
112
120
|
|
113
121
|
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
114
122
|
|
115
123
|
OperationId: ai_guard_post_v1beta_text_guard
|
116
124
|
|
117
125
|
Args:
|
118
|
-
text: Text
|
119
|
-
|
120
|
-
|
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
|
121
134
|
|
122
135
|
Examples:
|
123
136
|
response = ai_guard.guard_text("text")
|
124
137
|
"""
|
125
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
|
+
|
126
201
|
return self.request.post(
|
127
|
-
"v1beta/text/guard",
|
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
|
+
},
|
128
209
|
)
|
@@ -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
|
@@ -1,9 +1,9 @@
|
|
1
|
-
pangea/__init__.py,sha256=
|
1
|
+
pangea/__init__.py,sha256=wdTGmwo1JC7NzREP3iXJP02Jv2SYmmPLT543aYxuQeA,251
|
2
2
|
pangea/asyncio/__init__.py,sha256=kjEMkqMQ521LlMSu5jn3_WgweyArwVZ2C-s3x7mR6Pk,45
|
3
3
|
pangea/asyncio/file_uploader.py,sha256=wI7epib7Rc5jtZw4eJ1L1SlmutDG6CPv59C8N2UPhtY,1436
|
4
4
|
pangea/asyncio/request.py,sha256=lpLY-o405r3-VUfrAE5uxYxI8UjM4hjPqUzAUtOGE5o,18040
|
5
5
|
pangea/asyncio/services/__init__.py,sha256=L6Tdhjfx_ZECHskhLMPaCcOefi-r-imw6q_zlU4j-FY,464
|
6
|
-
pangea/asyncio/services/ai_guard.py,sha256=
|
6
|
+
pangea/asyncio/services/ai_guard.py,sha256=GNDXooxEvEkifNef9sPBaM6ymlwdogto6oLPf10gPgo,5601
|
7
7
|
pangea/asyncio/services/audit.py,sha256=rPaCx4cMzj-g9WFMRIysFCJAz6Btp6YrhcKe_exky8k,26283
|
8
8
|
pangea/asyncio/services/authn.py,sha256=rPeLJweL8mYH_t4ebcQn4n_Wglr3kClKNnCXNCimZU4,46622
|
9
9
|
pangea/asyncio/services/authz.py,sha256=B_0_nhDMJcjNpjpCx3Vi2LDRhlmfV9325GKbUZ8reos,10025
|
@@ -28,7 +28,7 @@ pangea/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
28
|
pangea/request.py,sha256=vGB8owXUiNQoeiiACFvfXvg44JJo_L6WfcHlF6ug8co,25082
|
29
29
|
pangea/response.py,sha256=lPAcYsF9Xg166CiyhCofVmQA-W4jevh0MQXxUa8Re68,7737
|
30
30
|
pangea/services/__init__.py,sha256=h36HzyIGaI5kO6l3UCwKHx_Kd-m_9mYVwn5MLRVzblI,408
|
31
|
-
pangea/services/ai_guard.py,sha256
|
31
|
+
pangea/services/ai_guard.py,sha256=Pe-j4WrMQg5fO8T6LkygQ1qwBWbN0Ha28aEHl4uw6dY,6905
|
32
32
|
pangea/services/audit/audit.py,sha256=7-c9l7jyGtpG7SqRUMpqsAzcUDhMZ5izgPalxHXsUvM,39320
|
33
33
|
pangea/services/audit/exceptions.py,sha256=bhVuYe4ammacOVxwg98CChxvwZf5FKgR2DcgqILOcwc,471
|
34
34
|
pangea/services/audit/models.py,sha256=1h1B9eSYQMYG3f8WNi1UcDX2-impRrET_ErjJYUnj7M,14678
|
@@ -55,6 +55,6 @@ pangea/services/vault/vault.py,sha256=ow-Zm7PYzfWIfUcA4UNnpeL2DHfZM4C7inRDmNR3zQ
|
|
55
55
|
pangea/tools.py,sha256=2-Y4SAHWFv6Ocj42J_bWrVy27M5G3wi7a8LJn0dabHc,6427
|
56
56
|
pangea/utils.py,sha256=dZ6MwFVEWXUgXvvDg-k6JnvVfsgslvtaBd7ez7afrqk,4983
|
57
57
|
pangea/verify_audit.py,sha256=nSP17OzoSPdvezRExwfcf45H8ZPZnxZu-CbEp3qFJO0,17354
|
58
|
-
pangea_sdk-5.
|
59
|
-
pangea_sdk-5.
|
60
|
-
pangea_sdk-5.
|
58
|
+
pangea_sdk-5.5.0b1.dist-info/METADATA,sha256=CHx5MOHw5eW7kRbPN0EzsggBDkqbcQApROvM-78tM1A,7011
|
59
|
+
pangea_sdk-5.5.0b1.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
60
|
+
pangea_sdk-5.5.0b1.dist-info/RECORD,,
|
File without changes
|