답변 1개
채택된 답변
+20 포인트
2년 전
1.curl을 사용하여 API 호출
</p>
<p>$url = "<a href="https://api.openai.com/v1/engines/davinci-codex/completions";" target="_blank" rel="noopener noreferrer">https://api.openai.com/v1/engines/davinci-codex/completions";</a>
$data = array(
"prompt" => "Your prompt text here",
"max_tokens" => 16
);
$headers = array(
"Content-Type: application/json",
"Authorization: Bearer YOUR_API_KEY"
);
$options = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true
);
$curl = curl_init();
curl_setopt_array($curl, $options);
$result = curl_exec($curl);
curl_close($curl);</p>
<p>
2.GuzzleHttp
</p>
<p>use GuzzleHttp\Client;</p>
<p>$client = new Client([
'base_uri' => '<a href="https://api.openai.com/v1/'," target="_blank" rel="noopener noreferrer">https://api.openai.com/v1/',</a>
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer YOUR_API_KEY'
]
]);
$response = $client->post('engines/davinci-codex/completions', [
'json' => [
'prompt' => 'Your prompt text here',
'max_tokens' => 16
]
]);
$result = $response->getBody()->getContents();</p>
<p>
위 예시에서 YOUR_API_KEY는 자신의 OpenAI API 키로 대체해야 합니다. 또한, prompt와 max_tokens는 Chat GPT API 호출에 필요한 매개변수입니다. 필요에 따라 추가적인 매개변수를 사용할 수 있습니다.
챗GPT 답변입니다.
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인