pangea-sdk 6.5.0b1__py3-none-any.whl → 6.7.0__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.
@@ -1,18 +1,21 @@
1
1
  from __future__ import annotations
2
2
 
3
- from collections.abc import Mapping
4
3
  from typing import TYPE_CHECKING, Annotated, Literal, Optional
5
4
 
6
- from pydantic import BaseModel, Field
5
+ from pydantic import Field
7
6
 
7
+ from pangea._typing import SequenceNotStr
8
8
  from pangea.config import PangeaConfig
9
- from pangea.response import APIRequestModel, APIResponseModel, PangeaDateTime, PangeaResponse, PangeaResponseResult
9
+ from pangea.response import APIRequestModel, APIResponseModel, PangeaResponse, PangeaResponseResult
10
10
  from pangea.services.base import ServiceBase
11
11
 
12
12
  if TYPE_CHECKING:
13
13
  from collections.abc import Iterable
14
14
 
15
15
 
16
+ __all__ = ("Message", "PromptGuard")
17
+
18
+
16
19
  class Message(APIRequestModel):
17
20
  role: str
18
21
  content: str
@@ -33,108 +36,21 @@ class GuardResult(PangeaResponseResult):
33
36
  detected: bool
34
37
  """Boolean response for if the prompt was considered malicious or not"""
35
38
 
39
+ analyzer: Optional[str] = None
40
+
36
41
  type: Optional[Literal["direct", "indirect", ""]] = None
37
42
  """Type of analysis, either direct or indirect"""
38
43
 
39
- analyzer: Optional[str] = None
40
- """Prompt Analyzers for identifying and rejecting properties of prompts"""
41
-
42
- confidence: float
44
+ confidence: Annotated[Optional[float], Field(ge=0.0, le=1.0)] = None
43
45
  """Percent of confidence in the detection result, ranging from 0 to 1"""
44
46
 
45
47
  info: Optional[str] = None
46
48
  """Extra information about the detection result"""
47
49
 
48
- classifications: list[Classification]
50
+ classifications: Optional[list[Classification]] = None
49
51
  """List of classification results with labels and confidence scores"""
50
52
 
51
53
 
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
-
138
54
  class PromptGuard(ServiceBase):
139
55
  """Prompt Guard service client.
140
56
 
@@ -178,7 +94,7 @@ class PromptGuard(ServiceBase):
178
94
  self,
179
95
  messages: Iterable[Message],
180
96
  *,
181
- analyzers: Iterable[str] | None = None,
97
+ analyzers: SequenceNotStr[str] | None = None,
182
98
  classify: bool | None = None,
183
99
  ) -> PangeaResponse[GuardResult]:
184
100
  """
@@ -205,105 +121,3 @@ class PromptGuard(ServiceBase):
205
121
  GuardResult,
206
122
  data={"messages": messages, "analyzers": analyzers, "classify": classify},
207
123
  )
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
- )