pangea-sdk 6.1.1__py3-none-any.whl → 6.2.0b2__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 +9 -1
- pangea/asyncio/__init__.py +1 -0
- pangea/asyncio/file_uploader.py +4 -2
- pangea/asyncio/request.py +199 -35
- pangea/asyncio/services/__init__.py +3 -0
- pangea/asyncio/services/ai_guard.py +91 -2
- pangea/asyncio/services/audit.py +307 -2
- pangea/asyncio/services/authn.py +12 -2
- pangea/asyncio/services/base.py +4 -0
- pangea/asyncio/services/file_scan.py +7 -1
- pangea/asyncio/services/intel.py +6 -2
- pangea/asyncio/services/management.py +576 -0
- pangea/asyncio/services/prompt_guard.py +112 -2
- pangea/asyncio/services/redact.py +269 -4
- pangea/asyncio/services/sanitize.py +5 -1
- pangea/asyncio/services/share.py +5 -1
- pangea/asyncio/services/vault.py +4 -0
- pangea/audit_logger.py +3 -1
- pangea/deep_verify.py +13 -13
- pangea/deprecated.py +1 -1
- pangea/dump_audit.py +2 -3
- pangea/exceptions.py +8 -5
- pangea/file_uploader.py +4 -0
- pangea/request.py +205 -52
- pangea/response.py +15 -12
- pangea/services/__init__.py +3 -0
- pangea/services/ai_guard.py +497 -16
- pangea/services/audit/audit.py +310 -8
- pangea/services/audit/models.py +279 -0
- pangea/services/audit/signing.py +1 -1
- pangea/services/audit/util.py +10 -10
- pangea/services/authn/authn.py +12 -2
- pangea/services/authn/models.py +3 -0
- pangea/services/authz.py +4 -0
- pangea/services/base.py +5 -1
- pangea/services/embargo.py +6 -0
- pangea/services/file_scan.py +7 -1
- pangea/services/intel.py +4 -0
- pangea/services/management.py +720 -0
- pangea/services/prompt_guard.py +193 -2
- pangea/services/redact.py +477 -7
- pangea/services/sanitize.py +5 -1
- pangea/services/share/share.py +13 -7
- pangea/services/vault/models/asymmetric.py +4 -0
- pangea/services/vault/models/common.py +4 -0
- pangea/services/vault/models/symmetric.py +4 -0
- pangea/services/vault/vault.py +2 -4
- pangea/tools.py +13 -9
- pangea/utils.py +3 -5
- pangea/verify_audit.py +23 -27
- {pangea_sdk-6.1.1.dist-info → pangea_sdk-6.2.0b2.dist-info}/METADATA +4 -4
- pangea_sdk-6.2.0b2.dist-info/RECORD +62 -0
- pangea_sdk-6.1.1.dist-info/RECORD +0 -60
- {pangea_sdk-6.1.1.dist-info → pangea_sdk-6.2.0b2.dist-info}/WHEEL +0 -0
pangea/services/prompt_guard.py
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from
|
3
|
+
from collections.abc import Mapping
|
4
|
+
from typing import TYPE_CHECKING, Annotated, Literal, Optional
|
5
|
+
|
6
|
+
from pydantic import BaseModel, Field
|
4
7
|
|
5
8
|
from pangea.config import PangeaConfig
|
6
|
-
from pangea.response import APIRequestModel, APIResponseModel, PangeaResponse, PangeaResponseResult
|
9
|
+
from pangea.response import APIRequestModel, APIResponseModel, PangeaDateTime, PangeaResponse, PangeaResponseResult
|
7
10
|
from pangea.services.base import ServiceBase
|
8
11
|
|
9
12
|
if TYPE_CHECKING:
|
@@ -46,6 +49,92 @@ class GuardResult(PangeaResponseResult):
|
|
46
49
|
"""List of classification results with labels and confidence scores"""
|
47
50
|
|
48
51
|
|
52
|
+
class Areas(BaseModel):
|
53
|
+
malicious_prompt: Optional[bool] = None
|
54
|
+
benign_prompt: Optional[bool] = None
|
55
|
+
|
56
|
+
|
57
|
+
class AuditDataActivityConfig(BaseModel):
|
58
|
+
enabled: bool
|
59
|
+
audit_service_config_id: str
|
60
|
+
areas: Areas
|
61
|
+
|
62
|
+
|
63
|
+
class ServiceConfig(BaseModel):
|
64
|
+
id: Optional[str] = None
|
65
|
+
version: Optional[str] = None
|
66
|
+
analyzers: Optional[dict[str, bool]] = None
|
67
|
+
malicious_detection_threshold: Annotated[Optional[float], Field(ge=0.0, le=1.0)] = None
|
68
|
+
benign_detection_threshold: Annotated[Optional[float], Field(ge=0.0, le=1.0)] = None
|
69
|
+
audit_data_activity: Optional[AuditDataActivityConfig] = None
|
70
|
+
|
71
|
+
|
72
|
+
class ServiceConfigFilter(BaseModel):
|
73
|
+
id: Optional[str] = None
|
74
|
+
"""
|
75
|
+
Only records where id equals this value.
|
76
|
+
"""
|
77
|
+
id__contains: Optional[list[str]] = None
|
78
|
+
"""
|
79
|
+
Only records where id includes each substring.
|
80
|
+
"""
|
81
|
+
id__in: Optional[list[str]] = None
|
82
|
+
"""
|
83
|
+
Only records where id equals one of the provided substrings.
|
84
|
+
"""
|
85
|
+
created_at: Optional[PangeaDateTime] = None
|
86
|
+
"""
|
87
|
+
Only records where created_at equals this value.
|
88
|
+
"""
|
89
|
+
created_at__gt: Optional[PangeaDateTime] = None
|
90
|
+
"""
|
91
|
+
Only records where created_at is greater than this value.
|
92
|
+
"""
|
93
|
+
created_at__gte: Optional[PangeaDateTime] = None
|
94
|
+
"""
|
95
|
+
Only records where created_at is greater than or equal to this value.
|
96
|
+
"""
|
97
|
+
created_at__lt: Optional[PangeaDateTime] = None
|
98
|
+
"""
|
99
|
+
Only records where created_at is less than this value.
|
100
|
+
"""
|
101
|
+
created_at__lte: Optional[PangeaDateTime] = None
|
102
|
+
"""
|
103
|
+
Only records where created_at is less than or equal to this value.
|
104
|
+
"""
|
105
|
+
updated_at: Optional[PangeaDateTime] = None
|
106
|
+
"""
|
107
|
+
Only records where updated_at equals this value.
|
108
|
+
"""
|
109
|
+
updated_at__gt: Optional[PangeaDateTime] = None
|
110
|
+
"""
|
111
|
+
Only records where updated_at is greater than this value.
|
112
|
+
"""
|
113
|
+
updated_at__gte: Optional[PangeaDateTime] = None
|
114
|
+
"""
|
115
|
+
Only records where updated_at is greater than or equal to this value.
|
116
|
+
"""
|
117
|
+
updated_at__lt: Optional[PangeaDateTime] = None
|
118
|
+
"""
|
119
|
+
Only records where updated_at is less than this value.
|
120
|
+
"""
|
121
|
+
updated_at__lte: Optional[PangeaDateTime] = None
|
122
|
+
"""
|
123
|
+
Only records where updated_at is less than or equal to this value.
|
124
|
+
"""
|
125
|
+
|
126
|
+
|
127
|
+
class ServiceConfigsPage(PangeaResponseResult):
|
128
|
+
count: Optional[int] = None
|
129
|
+
"""The total number of service configs matched by the list request."""
|
130
|
+
last: Optional[str] = None
|
131
|
+
"""
|
132
|
+
Used to fetch the next page of the current listing when provided in a
|
133
|
+
repeated request's last parameter.
|
134
|
+
"""
|
135
|
+
items: Optional[list[ServiceConfig]] = None
|
136
|
+
|
137
|
+
|
49
138
|
class PromptGuard(ServiceBase):
|
50
139
|
"""Prompt Guard service client.
|
51
140
|
|
@@ -116,3 +205,105 @@ class PromptGuard(ServiceBase):
|
|
116
205
|
GuardResult,
|
117
206
|
data={"messages": messages, "analyzers": analyzers, "classify": classify},
|
118
207
|
)
|
208
|
+
|
209
|
+
def get_service_config(
|
210
|
+
self,
|
211
|
+
*,
|
212
|
+
id: str | None = None,
|
213
|
+
version: str | None = None,
|
214
|
+
analyzers: Mapping[str, bool] | None = None,
|
215
|
+
malicious_detection_threshold: float | None = None,
|
216
|
+
benign_detection_threshold: float | None = None,
|
217
|
+
audit_data_activity: AuditDataActivityConfig | None = None,
|
218
|
+
) -> PangeaResponse[PangeaResponseResult]:
|
219
|
+
"""
|
220
|
+
OperationId: prompt_guard_post_v1beta_config
|
221
|
+
"""
|
222
|
+
return self.request.post(
|
223
|
+
"v1beta/config",
|
224
|
+
data={
|
225
|
+
"id": id,
|
226
|
+
"version": version,
|
227
|
+
"analyzers": analyzers,
|
228
|
+
"malicious_detection_threshold": malicious_detection_threshold,
|
229
|
+
"benign_detection_threshold": benign_detection_threshold,
|
230
|
+
"audit_data_activity": audit_data_activity,
|
231
|
+
},
|
232
|
+
result_class=PangeaResponseResult,
|
233
|
+
)
|
234
|
+
|
235
|
+
def create_service_config(
|
236
|
+
self,
|
237
|
+
*,
|
238
|
+
id: str | None = None,
|
239
|
+
version: str | None = None,
|
240
|
+
analyzers: Mapping[str, bool] | None = None,
|
241
|
+
malicious_detection_threshold: float | None = None,
|
242
|
+
benign_detection_threshold: float | None = None,
|
243
|
+
audit_data_activity: AuditDataActivityConfig | None = None,
|
244
|
+
) -> PangeaResponse[PangeaResponseResult]:
|
245
|
+
"""
|
246
|
+
OperationId: prompt_guard_post_v1beta_config_create
|
247
|
+
"""
|
248
|
+
return self.request.post(
|
249
|
+
"v1beta/config/create",
|
250
|
+
data={
|
251
|
+
"id": id,
|
252
|
+
"version": version,
|
253
|
+
"analyzers": analyzers,
|
254
|
+
"malicious_detection_threshold": malicious_detection_threshold,
|
255
|
+
"benign_detection_threshold": benign_detection_threshold,
|
256
|
+
"audit_data_activity": audit_data_activity,
|
257
|
+
},
|
258
|
+
result_class=PangeaResponseResult,
|
259
|
+
)
|
260
|
+
|
261
|
+
def update_service_config(
|
262
|
+
self,
|
263
|
+
*,
|
264
|
+
id: str | None = None,
|
265
|
+
version: str | None = None,
|
266
|
+
analyzers: Mapping[str, bool] | None = None,
|
267
|
+
malicious_detection_threshold: float | None = None,
|
268
|
+
benign_detection_threshold: float | None = None,
|
269
|
+
audit_data_activity: AuditDataActivityConfig | None = None,
|
270
|
+
) -> PangeaResponse[PangeaResponseResult]:
|
271
|
+
"""
|
272
|
+
OperationId: prompt_guard_post_v1beta_config_update
|
273
|
+
"""
|
274
|
+
return self.request.post(
|
275
|
+
"v1beta/config/update",
|
276
|
+
data={
|
277
|
+
"id": id,
|
278
|
+
"version": version,
|
279
|
+
"analyzers": analyzers,
|
280
|
+
"malicious_detection_threshold": malicious_detection_threshold,
|
281
|
+
"benign_detection_threshold": benign_detection_threshold,
|
282
|
+
"audit_data_activity": audit_data_activity,
|
283
|
+
},
|
284
|
+
result_class=PangeaResponseResult,
|
285
|
+
)
|
286
|
+
|
287
|
+
def delete_service_config(self, id: str) -> PangeaResponse[PangeaResponseResult]:
|
288
|
+
"""
|
289
|
+
OperationId: prompt_guard_post_v1beta_config_delete
|
290
|
+
"""
|
291
|
+
return self.request.post("v1beta/config/delete", data={"id": id}, result_class=PangeaResponseResult)
|
292
|
+
|
293
|
+
def list_service_configs(
|
294
|
+
self,
|
295
|
+
*,
|
296
|
+
filter: ServiceConfigFilter | None = None,
|
297
|
+
last: str | None = None,
|
298
|
+
order: Literal["asc", "desc"] | None = None,
|
299
|
+
order_by: Literal["id", "created_at", "updated_at"] | None = None,
|
300
|
+
size: int | None = None,
|
301
|
+
) -> PangeaResponse[ServiceConfigsPage]:
|
302
|
+
"""
|
303
|
+
OperationId: prompt_guard_post_v1beta_config_list
|
304
|
+
"""
|
305
|
+
return self.request.post(
|
306
|
+
"v1beta/config/list",
|
307
|
+
data={"filter": filter, "last": last, "order": order, "order_by": order_by, "size": size},
|
308
|
+
result_class=ServiceConfigsPage,
|
309
|
+
)
|