function getGPTAnswer($question)
{
$ch = curl_init();
$url = 'https://api.openai.com/v1/completions';
$api_key = '';
$post_fields = [
"model" => "text-davinci-003",
"prompt" => $question,
"max_tokens" => 1000,
"temperature" => 0.5
];
$header = [
'Content-Type: application/json',
'Authorization: Bearer ' . $api_key
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
}
curl_close($ch);
$response = json_decode($result);
//var_dump($result);
return $response->choices[0]->text;
}
May I know which country you are from? I am a Japanese living in Malaysia. I am OK if you could ship goods to either Malaysia or Japan. Thanks Tokuda
{"id":"cmpl-77oe6irjBRn8Ovxq2","object":"text_completion","created":1682097334,"model":"text-davinci-003","choices":[{"text":".","index":0,"logprobs":null,"finish_reason":"stop"}],"usage":{"prompt_tokens":46,"completion_tokens":1,"total_tokens":47}}