Skip to content

Commit f6b66e0

Browse files
Felipe Campos PenhaFelipe Campos Penha
authored andcommitted
refactor: lint.
1 parent c42b80f commit f6b66e0

File tree

1 file changed

+14
-17
lines changed
  • initiatives/genai_red_team_handbook/exploitation/example

1 file changed

+14
-17
lines changed
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import json
2-
import urllib.request
32
import sys
43
import tomllib
4+
import urllib.request
5+
56

67
def attack():
78
url = "http://localhost:8000/v1/chat/completions"
89
headers = {
910
"Content-Type": "application/json",
10-
"Authorization": "Bearer sk-mock-key"
11+
"Authorization": "Bearer sk-mock-key",
1112
}
12-
13+
1314
# Load prompt from configuration
1415
try:
1516
with open("config.toml", "rb") as f:
@@ -21,35 +22,31 @@ def attack():
2122
except Exception as e:
2223
print(f"[!] Error loading config: {e}")
2324
sys.exit(1)
24-
25+
2526
data = {
2627
"model": "gpt-oss:20b",
27-
"messages": [
28-
{"role": "user", "content": prompt}
29-
],
30-
"temperature": 0.7
28+
"messages": [{"role": "user", "content": prompt}],
29+
"temperature": 0.7,
3130
}
32-
31+
3332
try:
3433
req = urllib.request.Request(
35-
url,
36-
data=json.dumps(data).encode('utf-8'),
37-
headers=headers,
38-
method='POST'
34+
url, data=json.dumps(data).encode("utf-8"), headers=headers, method="POST"
3935
)
40-
36+
4137
print(f"[*] Sending adversarial prompt: {prompt}")
4238
with urllib.request.urlopen(req) as response:
43-
result = json.loads(response.read().decode('utf-8'))
44-
content = result['choices'][0]['message']['content']
39+
result = json.loads(response.read().decode("utf-8"))
40+
content = result["choices"][0]["message"]["content"]
4541
print(f"[*] Response received:\n{content}")
46-
42+
4743
except urllib.error.URLError as e:
4844
print(f"[!] Error communicating with API: {e}")
4945
sys.exit(1)
5046
except Exception as e:
5147
print(f"[!] Unexpected error: {e}")
5248
sys.exit(1)
5349

50+
5451
if __name__ == "__main__":
5552
attack()

0 commit comments

Comments
 (0)