<?php
$url = "https://api.openai.com/v1/completions";
$data = array('prompt' => $argv[1],'max_tokens' =>10, 'model'=> 'text-davinci-003','max_tokens'=>4000,'temperature'=> 1.0);
$encodedData = json_encode($data);
//$data = array(\"param1\" => \"value1\",\"param2\" => \"value2\"\);
$headers = array('Content-Type: application/json','Authorization:Bearer my-key-sdLwvCv');
$curl = curl_init();
$data_string = urlencode(json_encode($data));
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, 1);
//curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_POSTFIELDS, $encodedData);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
//echo $response; //uncoment this line if you need log info
$object=json_decode($response);
$array = (array) $object;
$response=(array)$array['choices'][0];
echo $response['text'];
echo "\n";
?>
No hay comentarios:
Publicar un comentario