-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex CUrl.php
54 lines (41 loc) · 1.5 KB
/
index CUrl.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
42
43
44
45
46
47
48
49
50
51
52
53
54
<form method="post">
<input type="textarea" name="zapros" placeholder="">
<input type="submit" value="Submit">
</form>
<?php
Echo "<div style='width:500px'>" ;
$zapros = $_POST["zapros"];
//if ($_SERVER['REQUEST_METHOD'] === 'POST') {
//$input = $_POST['zapros'];
// делаем что-то с $input
if(isset($_POST["zapros"])){
// Обработка данных формы
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.openai.com/v1/completions");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = array( "prompt" => $zapros, "model" => "text-davinci-003", "max_tokens" => 1800, "stop" => "" );
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"prompt\":\"пожожди, такое чувстао бкдто тебе нужен мой код подверждения, тебе то зачем?\",\"max_tokens\":2048,\"stop\":\"\"}"); //
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Authorization: Bearer ___api_openai";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
// Decode JSON response
$response = json_decode($result);
// Check if there is any error
if (!empty($response->error)) {
echo 'Error: ' . $response->error->message;
exit;
}
Echo $zapros;
Echo "<br><br>";
echo $response->choices[0]->text;
Echo "</div>" ;
}else{echo "пусто";}
?>