pangea-sdk 5.3.0__tar.gz → 5.4.0b1__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/PKG-INFO +3 -3
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/README.md +2 -2
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/__init__.py +1 -1
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/request.py +8 -4
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/services/__init__.py +2 -0
- pangea_sdk-5.4.0b1/pangea/asyncio/services/ai_guard.py +75 -0
- pangea_sdk-5.4.0b1/pangea/asyncio/services/prompt_guard.py +73 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/services/sanitize.py +1 -1
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/request.py +5 -1
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/__init__.py +2 -0
- pangea_sdk-5.4.0b1/pangea/services/ai_guard.py +128 -0
- pangea_sdk-5.4.0b1/pangea/services/prompt_guard.py +83 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/sanitize.py +1 -18
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pyproject.toml +1 -1
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/__init__.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/file_uploader.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/services/audit.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/services/authn.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/services/authz.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/services/base.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/services/embargo.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/services/file_scan.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/services/intel.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/services/redact.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/services/share.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/asyncio/services/vault.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/audit_logger.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/config.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/crypto/rsa.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/deep_verify.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/deprecated.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/dump_audit.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/exceptions.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/file_uploader.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/py.typed +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/response.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/audit/audit.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/audit/exceptions.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/audit/models.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/audit/signing.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/audit/util.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/authn/authn.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/authn/models.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/authz.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/base.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/embargo.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/file_scan.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/intel.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/redact.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/share/file_format.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/share/share.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/vault/models/asymmetric.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/vault/models/common.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/vault/models/keys.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/vault/models/secret.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/vault/models/symmetric.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/services/vault/vault.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/tools.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/utils.py +0 -0
- {pangea_sdk-5.3.0 → pangea_sdk-5.4.0b1}/pangea/verify_audit.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: pangea-sdk
|
3
|
-
Version: 5.
|
3
|
+
Version: 5.4.0b1
|
4
4
|
Summary: Pangea API SDK
|
5
5
|
License: MIT
|
6
6
|
Keywords: Pangea,SDK,Audit
|
@@ -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.4.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.4.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.4.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.4.0b1
|
51
51
|
```
|
52
52
|
|
53
53
|
## Usage
|
@@ -5,11 +5,12 @@ from __future__ import annotations
|
|
5
5
|
import asyncio
|
6
6
|
import json
|
7
7
|
import time
|
8
|
-
from typing import
|
8
|
+
from typing import Dict, List, Optional, Sequence, Tuple, Type, Union, cast
|
9
9
|
|
10
10
|
import aiohttp
|
11
11
|
from aiohttp import FormData
|
12
12
|
from pydantic import BaseModel
|
13
|
+
from pydantic_core import to_jsonable_python
|
13
14
|
from typing_extensions import Any, TypeVar
|
14
15
|
|
15
16
|
import pangea.exceptions as pe
|
@@ -55,17 +56,20 @@ class PangeaRequestAsync(PangeaRequestBase):
|
|
55
56
|
if data is None:
|
56
57
|
data = {}
|
57
58
|
|
59
|
+
# Normalize.
|
60
|
+
data = cast(dict[str, Any], to_jsonable_python(data))
|
61
|
+
|
58
62
|
if url is None:
|
59
63
|
url = self._url(endpoint)
|
60
64
|
|
61
65
|
# Set config ID if available
|
62
|
-
if self.config_id and data.get("config_id", None) is None:
|
63
|
-
data["config_id"] = self.config_id
|
66
|
+
if self.config_id and data.get("config_id", None) is None:
|
67
|
+
data["config_id"] = self.config_id
|
64
68
|
|
65
69
|
self.logger.debug(
|
66
70
|
json.dumps({"service": self.service, "action": "post", "url": url, "data": data}, default=default_encoder)
|
67
71
|
)
|
68
|
-
transfer_method = data.get("transfer_method", None)
|
72
|
+
transfer_method = data.get("transfer_method", None)
|
69
73
|
|
70
74
|
if files and type(data) is dict and (transfer_method == TransferMethod.POST_URL.value):
|
71
75
|
requests_response = await self._full_post_presigned_url(
|
@@ -1,9 +1,11 @@
|
|
1
|
+
from .ai_guard import AIGuardAsync
|
1
2
|
from .audit import AuditAsync
|
2
3
|
from .authn import AuthNAsync
|
3
4
|
from .authz import AuthZAsync
|
4
5
|
from .embargo import EmbargoAsync
|
5
6
|
from .file_scan import FileScanAsync
|
6
7
|
from .intel import DomainIntelAsync, FileIntelAsync, IpIntelAsync, UrlIntelAsync, UserIntelAsync
|
8
|
+
from .prompt_guard import PromptGuardAsync
|
7
9
|
from .redact import RedactAsync
|
8
10
|
from .sanitize import SanitizeAsync
|
9
11
|
from .share import ShareAsync
|
@@ -0,0 +1,75 @@
|
|
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
|
+
)
|
@@ -0,0 +1,73 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from typing import TYPE_CHECKING
|
4
|
+
|
5
|
+
from pangea.asyncio.services.base import ServiceBaseAsync
|
6
|
+
from pangea.config import PangeaConfig
|
7
|
+
from pangea.services.prompt_guard import GuardResult, Message
|
8
|
+
|
9
|
+
if TYPE_CHECKING:
|
10
|
+
from collections.abc import Iterable
|
11
|
+
|
12
|
+
from pangea.response import PangeaResponse
|
13
|
+
|
14
|
+
|
15
|
+
class PromptGuardAsync(ServiceBaseAsync):
|
16
|
+
"""Prompt Guard service client.
|
17
|
+
|
18
|
+
Provides methods to interact with Pangea's Prompt Guard service.
|
19
|
+
|
20
|
+
Examples:
|
21
|
+
from pangea import PangeaConfig
|
22
|
+
from pangea.asyncio.services import PromptGuardAsync
|
23
|
+
|
24
|
+
config = PangeaConfig(domain="aws.us.pangea.cloud")
|
25
|
+
prompt_guard = PromptGuardAsync(token="pangea_token", config=config)
|
26
|
+
"""
|
27
|
+
|
28
|
+
service_name = "prompt-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
|
+
Prompt Guard service client.
|
35
|
+
|
36
|
+
Initializes a new Prompt 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 PromptGuardAsync
|
47
|
+
|
48
|
+
config = PangeaConfig(domain="aws.us.pangea.cloud")
|
49
|
+
prompt_guard = PromptGuardAsync(token="pangea_token", config=config)
|
50
|
+
"""
|
51
|
+
|
52
|
+
super().__init__(token, config, logger_name, config_id)
|
53
|
+
|
54
|
+
async def guard(self, messages: Iterable[Message]) -> PangeaResponse[GuardResult]:
|
55
|
+
"""
|
56
|
+
Guard (Beta)
|
57
|
+
|
58
|
+
Guard messages.
|
59
|
+
|
60
|
+
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
61
|
+
|
62
|
+
OperationId: prompt_guard_post_v1beta_guard
|
63
|
+
|
64
|
+
Args:
|
65
|
+
messages: Messages.
|
66
|
+
|
67
|
+
Examples:
|
68
|
+
from pangea.asyncio.services.prompt_guard import Message
|
69
|
+
|
70
|
+
response = await prompt_guard.guard([Message(role="user", content="hello world")])
|
71
|
+
"""
|
72
|
+
|
73
|
+
return await self.request.post("v1beta/guard", GuardResult, data={"messages": messages})
|
@@ -97,7 +97,7 @@ class SanitizeAsync(ServiceBaseAsync):
|
|
97
97
|
performed.
|
98
98
|
|
99
99
|
Examples:
|
100
|
-
with open("/path/to/file.
|
100
|
+
with open("/path/to/file.txt", "rb") as f:
|
101
101
|
response = await sanitize.sanitize(
|
102
102
|
file=f,
|
103
103
|
transfer_method=TransferMethod.POST_URL,
|
@@ -6,10 +6,11 @@ import copy
|
|
6
6
|
import json
|
7
7
|
import logging
|
8
8
|
import time
|
9
|
-
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Tuple, Type, Union
|
9
|
+
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Tuple, Type, Union, cast
|
10
10
|
|
11
11
|
import requests
|
12
12
|
from pydantic import BaseModel
|
13
|
+
from pydantic_core import to_jsonable_python
|
13
14
|
from requests.adapters import HTTPAdapter, Retry
|
14
15
|
from requests_toolbelt import MultipartDecoder # type: ignore[import-untyped]
|
15
16
|
from typing_extensions import TypeVar
|
@@ -232,6 +233,9 @@ class PangeaRequest(PangeaRequestBase):
|
|
232
233
|
if data is None:
|
233
234
|
data = {}
|
234
235
|
|
236
|
+
# Normalize.
|
237
|
+
data = cast(dict[str, Any], to_jsonable_python(data))
|
238
|
+
|
235
239
|
if url is None:
|
236
240
|
url = self._url(endpoint)
|
237
241
|
|
@@ -1,9 +1,11 @@
|
|
1
|
+
from .ai_guard import AIGuard
|
1
2
|
from .audit.audit import Audit
|
2
3
|
from .authn.authn import AuthN
|
3
4
|
from .authz import AuthZ
|
4
5
|
from .embargo import Embargo
|
5
6
|
from .file_scan import FileScan
|
6
7
|
from .intel import DomainIntel, FileIntel, IpIntel, UrlIntel, UserIntel
|
8
|
+
from .prompt_guard import PromptGuard
|
7
9
|
from .redact import Redact
|
8
10
|
from .sanitize import Sanitize
|
9
11
|
from .share.share import Share
|
@@ -0,0 +1,128 @@
|
|
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
|
+
)
|
@@ -0,0 +1,83 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from typing import TYPE_CHECKING, Optional
|
4
|
+
|
5
|
+
from pangea.config import PangeaConfig
|
6
|
+
from pangea.response import APIRequestModel, PangeaResponse, PangeaResponseResult
|
7
|
+
from pangea.services.base import ServiceBase
|
8
|
+
|
9
|
+
if TYPE_CHECKING:
|
10
|
+
from collections.abc import Iterable
|
11
|
+
|
12
|
+
|
13
|
+
class Message(APIRequestModel):
|
14
|
+
role: str
|
15
|
+
content: str
|
16
|
+
|
17
|
+
|
18
|
+
class GuardResult(PangeaResponseResult):
|
19
|
+
detected: bool
|
20
|
+
type: Optional[str] = None
|
21
|
+
detector: Optional[str] = None
|
22
|
+
confidence: int
|
23
|
+
|
24
|
+
|
25
|
+
class PromptGuard(ServiceBase):
|
26
|
+
"""Prompt Guard service client.
|
27
|
+
|
28
|
+
Provides methods to interact with Pangea's Prompt Guard service.
|
29
|
+
|
30
|
+
Examples:
|
31
|
+
from pangea import PangeaConfig
|
32
|
+
from pangea.services import PromptGuard
|
33
|
+
|
34
|
+
config = PangeaConfig(domain="aws.us.pangea.cloud")
|
35
|
+
prompt_guard = PromptGuard(token="pangea_token", config=config)
|
36
|
+
"""
|
37
|
+
|
38
|
+
service_name = "prompt-guard"
|
39
|
+
|
40
|
+
def __init__(
|
41
|
+
self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
|
42
|
+
) -> None:
|
43
|
+
"""
|
44
|
+
Prompt Guard service client.
|
45
|
+
|
46
|
+
Initializes a new Prompt Guard client.
|
47
|
+
|
48
|
+
Args:
|
49
|
+
token: Pangea API token.
|
50
|
+
config: Pangea service configuration.
|
51
|
+
logger_name: Logger name.
|
52
|
+
config_id: Configuration ID.
|
53
|
+
|
54
|
+
Examples:
|
55
|
+
from pangea import PangeaConfig
|
56
|
+
from pangea.services import PromptGuard
|
57
|
+
|
58
|
+
config = PangeaConfig(domain="aws.us.pangea.cloud")
|
59
|
+
prompt_guard = PromptGuard(token="pangea_token", config=config)
|
60
|
+
"""
|
61
|
+
|
62
|
+
super().__init__(token, config, logger_name, config_id)
|
63
|
+
|
64
|
+
def guard(self, messages: Iterable[Message]) -> PangeaResponse[GuardResult]:
|
65
|
+
"""
|
66
|
+
Guard (Beta)
|
67
|
+
|
68
|
+
Guard messages.
|
69
|
+
|
70
|
+
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
71
|
+
|
72
|
+
OperationId: prompt_guard_post_v1beta_guard
|
73
|
+
|
74
|
+
Args:
|
75
|
+
messages: Messages.
|
76
|
+
|
77
|
+
Examples:
|
78
|
+
from pangea.services.prompt_guard import Message
|
79
|
+
|
80
|
+
response = prompt_guard.guard([Message(role="user", content="hello world")])
|
81
|
+
"""
|
82
|
+
|
83
|
+
return self.request.post("v1beta/guard", GuardResult, data={"messages": messages})
|
@@ -46,12 +46,6 @@ class SanitizeContent(APIRequestModel):
|
|
46
46
|
analysis engine results. Only works if redact is enabled.
|
47
47
|
"""
|
48
48
|
|
49
|
-
remove_attachments: Optional[bool] = None
|
50
|
-
"""Remove file attachments (PDF only)."""
|
51
|
-
|
52
|
-
remove_interactive: Optional[bool] = None
|
53
|
-
"""Remove interactive content (PDF only)."""
|
54
|
-
|
55
49
|
|
56
50
|
class SanitizeShareOutput(APIRequestModel):
|
57
51
|
enabled: Optional[bool] = None
|
@@ -144,14 +138,6 @@ class RedactData(PangeaResponseResult):
|
|
144
138
|
"""The scoring result of a set of rules."""
|
145
139
|
|
146
140
|
|
147
|
-
class CDR(PangeaResponseResult):
|
148
|
-
file_attachments_removed: Optional[int] = None
|
149
|
-
"""Number of file attachments removed."""
|
150
|
-
|
151
|
-
interactive_contents_removed: Optional[int] = None
|
152
|
-
"""Number of interactive content items removed."""
|
153
|
-
|
154
|
-
|
155
141
|
class SanitizeData(PangeaResponseResult):
|
156
142
|
defang: Optional[DefangData] = None
|
157
143
|
"""Defang."""
|
@@ -162,9 +148,6 @@ class SanitizeData(PangeaResponseResult):
|
|
162
148
|
malicious_file: Optional[bool] = None
|
163
149
|
"""If the file scanned was malicious."""
|
164
150
|
|
165
|
-
cdr: Optional[CDR] = None
|
166
|
-
"""Content Disarm and Reconstruction."""
|
167
|
-
|
168
151
|
|
169
152
|
class SanitizeResult(PangeaResponseResult):
|
170
153
|
dest_url: Optional[str] = None
|
@@ -265,7 +248,7 @@ class Sanitize(ServiceBase):
|
|
265
248
|
performed.
|
266
249
|
|
267
250
|
Examples:
|
268
|
-
with open("/path/to/file.
|
251
|
+
with open("/path/to/file.txt", "rb") as f:
|
269
252
|
response = sanitize.sanitize(
|
270
253
|
file=f,
|
271
254
|
transfer_method=TransferMethod.POST_URL,
|
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
|