Create appp.py
Browse files
appp.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
# Define the prompt to be sent
|
| 4 |
+
prompt = 'Please generate a simple blog post according to this title "What is CHATGPT"'
|
| 5 |
+
|
| 6 |
+
# Enter E-mail to generate API
|
| 7 |
+
api_key = 'Enter your E-mail Address to get the free ChatGPT API'
|
| 8 |
+
|
| 9 |
+
# Define the default model if none is specified
|
| 10 |
+
default_model = 'gpt-3.5-turbo'
|
| 11 |
+
|
| 12 |
+
# Uncomment the model you want to use, and comment out the others
|
| 13 |
+
# model = 'gpt-4'
|
| 14 |
+
# model = 'gpt-4-32k'
|
| 15 |
+
# model = 'gpt-3.5-turbo-0125'
|
| 16 |
+
model = default_model
|
| 17 |
+
|
| 18 |
+
# Build the URL to call
|
| 19 |
+
api_url = f'http://195.179.229.119/gpt/api.php?prompt={requests.utils.quote(prompt)}&api_key={requests.utils.quote(api_key)}&model={requests.utils.quote(model)}'
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
# Execute the HTTP request
|
| 23 |
+
response = requests.get(api_url)
|
| 24 |
+
response.raise_for_status() # Raise an error for bad HTTP status codes
|
| 25 |
+
|
| 26 |
+
# Parse and print the response
|
| 27 |
+
data = response.json()
|
| 28 |
+
print(data)
|
| 29 |
+
|
| 30 |
+
except requests.RequestException as e:
|
| 31 |
+
# Print any errors
|
| 32 |
+
print(f'Request Error: {e}')
|