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
'!!...PHP > !!...SAMPLE' 카테고리의 다른 글
[PHP]16_curl 을 이용한 파일 전송 샘플코드 (0) | 2023.02.13 |
---|---|
[PHP]15_http reqeust sample code (0) | 2023.02.08 |
[PHP]13_shell_exec Sample Code (0) | 2022.12.23 |
[PHP]12_문법예제 * 를 이용하여 다이아몬드 모양 출력하기 (0) | 2022.12.22 |
[PHP]11_특정 디렉토리 파일 목록 출력 (0) | 2022.10.20 |