Skip to content

Commit d374351

Browse files
authored
Create gptchat.php
1 parent 3f86fdd commit d374351

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

gptchat.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
header('Content-Type: application/json');
3+
header('Access-Control-Allow-Origin: *');
4+
header('Access-Control-Allow-Methods: POST');
5+
header('Access-Control-Allow-Headers: Content-Type, Authorization');
6+
7+
// Replace YOUR_API_KEY with your actual GPTChat API key
8+
define('API_KEY', 'YOUR_API_KEY');
9+
10+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
11+
$input = json_decode(file_get_contents('php://input'), true);
12+
$message = urlencode($input['message']);
13+
14+
$url = "https://api.gptchat.com/v1/engines/gpt-4/complete?api_key=" . API_KEY . "&message=" . $message;
15+
16+
$response = file_get_contents($url);
17+
echo $response;
18+
} else {
19+
http_response_code(405);
20+
echo json_encode(['error' => 'Method not allowed']);
21+
}

0 commit comments

Comments
 (0)