<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.openai.com/v1/chat/completions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer $API_KEY',
'Content-Type: application/json',
]);
$model="gpt-3.5-turbo";
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"model\": \"$model\",\n \"messages\": [{\"role\": \"user\", \"content\": \"$argv[1]\"}] \n }");
$response = curl_exec($ch);
$object=json_decode($response);
$array = json_decode(json_encode($object), true);
//print_r($array); //uncoment for details
echo $array['choices'][0]['message']['content'];
echo "\n";
curl_close($ch);
?>
curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}'
No hay comentarios:
Publicar un comentario