-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathphp-working-api.php
41 lines (32 loc) · 1.15 KB
/
php-working-api.php
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
37
38
39
40
41
<?php
// Define the prompt to be sent
$prompt = 'Please generate a simple blog post according to this title "What is CHATGPT"';
// Enter E-mail to generate API
// Get API Key from: https://hdstockimages.com/get-free-openai-chatgpt-api/
$apiKey = 'Enter your E-mail Address to get the free ChatGPT API';
// Define the default model if none is specified
$defaultModel = 'gpt-3.5-turbo';
// Uncomment the model you want to use, and comment out the others
// $model = 'gpt-4';
// $model = 'gpt-4-32k';
// $model = 'gpt-3.5-turbo-0125';
$model = $defaultModel;
// Build the URL to call
$apiUrl = 'http://195.179.229.119/gpt/api.php?prompt=' . urlencode($prompt) . '&api_key=' . urlencode($apiKey) . '&model=' . urlencode($model);
// Initialize cURL session
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the cURL request
$response = curl_exec($ch);
// Check for cURL errors
if ($response === false) {
echo 'cURL Error: ' . htmlspecialchars(curl_error($ch));
} else {
$data = json_decode($response, true);
print_r($data);
}
// Close the cURL session
curl_close($ch);
?>