Skip to content

Commit b9da94d

Browse files
[pentest] add better README
1 parent c962834 commit b9da94d

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

README.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,68 @@ A more detailed documentation is available at [docs.zenguard.ai](https://docs.ze
4040

4141
# Pentesting
4242

43-
You can run pentest against both ZenGuard AI and (optionally) ChatGPT.
43+
Run pentest against both ZenGuard AI and (optionally) ChatGPT.
44+
45+
We are using the modified version of the [PromptInject](https://github.com/agencyenterprise/PromptInject/tree/main) as the basic framework for building prompt injections.
46+
47+
Note that we are always running the pentest against the most up-to-date models, such as:
48+
49+
* ZenGuard AI: latest release
50+
* ChatGPT: `gpt-4-0125-preview`
51+
52+
### Using `zenguard` library
53+
54+
Pentest against ZenGuard AI:
55+
56+
```python
57+
import os
58+
59+
from zenguard import (
60+
Credentials,
61+
Detector,
62+
Endpoint,
63+
ZenGuard,
64+
ZenGuardConfig,
65+
)
66+
67+
if __name__ == "__main__":
68+
api_key = os.environ.get("ZEN_API_KEY")
69+
if not api_key:
70+
raise ValueError("ZEN_API_KEY is not set")
71+
72+
config = ZenGuardConfig(credentials=Credentials(api_key=api_key))
73+
zenguard = ZenGuard(config=config)
74+
zenguard.pentest(endpoint=Endpoint.ZENGUARD, detector=Detector.PROMPT_INJECTION)
75+
```
76+
77+
Pentest against ZenGuard AI and ChatGPT:
78+
79+
```python
80+
import os
81+
82+
from zenguard import (
83+
Credentials,
84+
Detector,
85+
Endpoint,
86+
SupportedLLMs,
87+
ZenGuard,
88+
ZenGuardConfig,
89+
)
90+
91+
if __name__ == "__main__":
92+
api_key = os.environ.get("ZEN_API_KEY")
93+
openai_api_key = os.environ.get("OPENAI_API_KEY")
94+
if not api_key or not openai_api_key:
95+
raise ValueError("API keys are not set")
96+
97+
config = ZenGuardConfig(credentials=Credentials(api_key=api_key, llm_api_key=opena_api_key), llm=SupporedLLMs.CHATGPT)
98+
zenguard = ZenGuard(config=config)
99+
zenguard.pentest(endpoint=Endpoint.ZENGUARD, detector=Detector.PROMPT_INJECTION)
100+
zenguard.pentest(endpoint=Endpoint.OPENAI, detector=Detector.PROMPT_INJECTION)
101+
```
102+
103+
104+
### Using pentest script
44105

45106
Clone this repo and install requirements.
46107

@@ -59,7 +120,6 @@ python tests/pentest.py
59120
```
60121

61122

62-
Note that we always are running the pentest against the most up-to-date model. Currently, `gpt-4-0125-preview`
63123

64124

65125

zenguard/zenguard.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ def pentest(self, endpoint: Endpoint, detector: Detector = None):
100100
attack_prompts = prompting.build_prompts(base_prompts)
101101

102102
if endpoint == Endpoint.ZENGUARD:
103-
print("Running attack on ZenGuard endpoint")
103+
print("\nRunning attack on ZenGuard endpoint:")
104104
assert (
105105
detector == Detector.PROMPT_INJECTION
106106
), "Only prompt injection pentesting is currently supported"
107107
self._attack_zenguard(Detector.PROMPT_INJECTION, attack_prompts)
108108
elif endpoint == Endpoint.OPENAI:
109-
print("Running attack on OpenAI endpoint")
109+
print("\nRunning attack on OpenAI endpoint:")
110110
run.run_prompts_api(attack_prompts, self._llm_client)
111111

112112
scoring.score_attacks(attack_prompts)

0 commit comments

Comments
 (0)