forked from patrickrchao/JailbreakingLLMs
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgeminiapicheck.py
More file actions
36 lines (31 loc) · 851 Bytes
/
geminiapicheck.py
File metadata and controls
36 lines (31 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import requests
import json
# not working yet
# Define the API key and URL
api_key = "GEMINI_API_KEY"
url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key={api_key}"
# Define the headers and the payload
headers = {
"Content-Type": "application/json"
}
payload = {
"contents": [
{
"parts": [
{
"text": "Explain how AI works"
}
]
}
]
}
# Make the POST request
try:
response = requests.post(url, headers=headers, data=json.dumps(payload))
# Check if the request was successful
if response.status_code == 200:
print("Response:", response.json())
else:
print(f"Error {response.status_code}: {response.text}")
except Exception as e:
print("An error occurred:", e)