BIG

 


<?php

$api_key = "YOUR_API_KEY";
$model = "YOUR_MODEL_NAME";

$prompt = "What is the capital of France?";

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.openai.com/v1/engines/".$model."/jobs",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS =>"{\"prompt\":\"".$prompt."\",\"max_tokens\":1024,\"temperature\":0.5}",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Bearer ".$api_key,
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

//----------------------------------------------------------------------

<?php

$ch = curl_init();

$apiKey = "YOUR_API_KEY";
$model = "text-davinci-002";
$prompt = "What is the meaning of life?";

curl_setopt($ch, CURLOPT_URL, "https://api.openai.com/v1/engines/$model/jobs");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"prompt\":\"$prompt\"}");
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Authorization: Bearer $apiKey";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);

$resultJson = json_decode($result);
$generatedText = $resultJson->choices[0]->text;

echo $generatedText;
LIST