Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- AI Guard and Prompt Guard services.

### Changed

- Clarified what `PangeaConfig.environment` affects.
Expand Down
4 changes: 4 additions & 0 deletions examples/.examples-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
matrix:
- PYTHON_VERSION: ["3.9", "3.10", "3.11", "3.12", "3.13"]
EXAMPLE_FOLDER:
- ai_guard
- audit
- authn
- authz
- embargo
- file_scan
- intel
- prompt_guard
- redact
- sanitize
- vault
- share
image: python:${PYTHON_VERSION}-bookworm
before_script:
- export PANGEA_AI_GUARD_TOKEN="${PANGEA_INTEGRATION_TOKEN_LVE_AWS}"
- export PANGEA_AUDIT_AUTH0_CONFIG_ID="${PANGEA_AUDIT_CONFIG_ID_3_LVE_AWS}"
- export PANGEA_AUDIT_CONFIG_ID="${PANGEA_AUDIT_CONFIG_ID_1_LVE_AWS}"
- export PANGEA_AUDIT_CUSTOM_SCHEMA_TOKEN="${PANGEA_INTEGRATION_CUSTOM_SCHEMA_TOKEN_LVE_AWS}"
Expand All @@ -28,6 +31,7 @@
- export PANGEA_EMBARGO_TOKEN="${PANGEA_INTEGRATION_TOKEN_LVE_AWS}"
- export PANGEA_FILE_SCAN_TOKEN="${PANGEA_INTEGRATION_TOKEN_LVE_AWS}"
- export PANGEA_INTEL_TOKEN="${PANGEA_INTEGRATION_TOKEN_LVE_AWS}"
- export PANGEA_PROMPT_GUARD_TOKEN="${PANGEA_INTEGRATION_TOKEN_LVE_AWS}"
- export PANGEA_REDACT_CONFIG_ID="${PANGEA_REDACT_CONFIG_ID_1_LVE_AWS}"
- export PANGEA_REDACT_MULTICONFIG_TOKEN="${PANGEA_INTEGRATION_MULTI_CONFIG_TOKEN_LVE_AWS}"
- export PANGEA_REDACT_TOKEN="${PANGEA_INTEGRATION_TOKEN_LVE_AWS}"
Expand Down
27 changes: 27 additions & 0 deletions examples/ai_guard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Pangea Python SDK examples

This is a quick example of how to set up and use the Pangea Python SDK.

## Set up

In the example root directory (`./examples/ai_guard`), run the following command:

```
poetry install
```

[Set up the environment variables][set-environment-variables]
`PANGEA_AI_GUARD_TOKEN` and `PANGEA_DOMAIN` with your project token configured
on the Pangea User Console (token should [have access to][configure-a-pangea-service]
the AI Guard service) and with your Pangea domain.

## Run

To run examples:

```
poetry run python ai_guard_examples/guard.py
```

[configure-a-pangea-service]: https://pangea.cloud/docs/getting-started/configure-services/#configure-a-pangea-service
[set-environment-variables]: https://pangea.cloud/docs/getting-started/integrate/#set-environment-variables
Empty file.
25 changes: 25 additions & 0 deletions examples/ai_guard/ai_guard_examples/guard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import annotations

import os

from pangea import PangeaConfig
from pangea.services.ai_guard import AIGuard

token = os.getenv("PANGEA_AI_GUARD_TOKEN", "")
domain = os.getenv("PANGEA_DOMAIN", "aws.us.pangea.cloud")

ai_guard = AIGuard(token, config=PangeaConfig(domain=domain))

# Text guard.
input_text = "This email address, security@pangea.cloud, will be redacted."
print("Guarding text:", input_text)
text_response = ai_guard.guard_text(input_text)
assert text_response.result
print("Response:", text_response.result.prompt_text)

# Structured input.
structured_input = [{"role": "user", "content": "hello world"}]
print("Guarding structured input:", structured_input)
structured_response = ai_guard.guard_text(messages=structured_input)
assert structured_response.result
print("Response:", structured_response.result.prompt_messages)
1,481 changes: 1,481 additions & 0 deletions examples/ai_guard/poetry.lock

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions examples/ai_guard/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[project]
name = "ai-guard-examples"
requires-python = ">=3.9"
dependencies = [
"pangea-sdk"
]

[tool.poetry]
package-mode = false

[tool.poetry.dependencies]
python = "^3.9.20"
pangea-sdk = { path = "../../packages/pangea-sdk", develop = true }

[tool.poetry.group.dev.dependencies]
black = "^24.8.0"
isort = "^5.13.2"
mypy = "^1.11.2"

[tool.black]
line-length = 120

[tool.isort]
profile = "black"
27 changes: 27 additions & 0 deletions examples/asyncio/ai_guard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Pangea Python SDK examples

This is a quick example of how to set up and use the Pangea Python SDK.

## Set up

In the example root directory (`./examples/asyncio/ai_guard`), run the following command:

```
poetry install
```

[Set up the environment variables][set-environment-variables]
`PANGEA_AI_GUARD_TOKEN` and `PANGEA_DOMAIN` with your project token configured
on the Pangea User Console (token should [have access to][configure-a-pangea-service]
the AI Guard service) and with your Pangea domain.

## Run

To run examples:

```
poetry run python ai_guard_examples/guard.py
```

[configure-a-pangea-service]: https://pangea.cloud/docs/getting-started/configure-services/#configure-a-pangea-service
[set-environment-variables]: https://pangea.cloud/docs/getting-started/integrate/#set-environment-variables
Empty file.
32 changes: 32 additions & 0 deletions examples/asyncio/ai_guard/ai_guard_examples/guard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from __future__ import annotations

import asyncio
import os

from pangea import PangeaConfig
from pangea.asyncio.services import AIGuardAsync

token = os.getenv("PANGEA_AI_GUARD_TOKEN", "")
domain = os.getenv("PANGEA_DOMAIN", "aws.us.pangea.cloud")

ai_guard = AIGuardAsync(token, config=PangeaConfig(domain=domain))


async def main() -> None:
# Text guard.
input_text = "This email address, security@pangea.cloud, will be redacted."
print("Guarding text:", input_text)
text_response = await ai_guard.guard_text(input_text)
assert text_response.result
print("Response:", text_response.result.prompt_text)

# Structured input.
structured_input = [{"role": "user", "content": "hello world"}]
print("Guarding structured input:", structured_input)
structured_response = await ai_guard.guard_text(messages=structured_input)
assert structured_response.result
print("Response:", structured_response.result.prompt_messages)


if __name__ == "__main__":
asyncio.run(main())
Loading
Loading