-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopenai.php
More file actions
35 lines (32 loc) · 1.08 KB
/
openai.php
File metadata and controls
35 lines (32 loc) · 1.08 KB
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
<?php
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
if (isset($_POST['str'])) {
$ch = curl_init();
$str = $_POST['str'];
curl_setopt($ch, CURLOPT_URL, 'https://api.openai.com/v1/completions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$postdata = array(
"model" => "text-davinci-003",
"prompt" => "$str",
"temperature" => 0,
"max_tokens" => 150,
"top_p" => 1.0,
"frequency_penalty" => 0.0,
"presence_penalty" => 0.0,
"stop" => ["\"\"\""]
);
$postdata = json_encode($postdata);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer 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';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$result = json_decode($result, true);
// echo '<pre>';
}