chatGPT 활용한 댓글 답변 게시판
해당 경로 파일에, 아래 소스코드 추가
// CHATGPT 추가 시작
if ($chatgpt){ //CHATGPT 요청
$api_key = $config['cf_1'];
$url = "https://api.openai.com/v1/chat/completions";
$post_fields = array(
"model" => "gpt-3.5-turbo",
"messages" => array(
array(
"role" => "user",
"content" => $wr_content
)
),
"max_tokens" => 4000,
"temperature" => 0
);
$header = [
'Content-Type: application/json',
'Authorization: Bearer ' . $api_key
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
}
curl_close($ch);
$result_json = json_decode($result, true);
$wr_link2 = $result_json["choices"][0]["message"]['content'];
}
// CHATGPT 추가 끝
관련링크
https://platform.openai.com/api-keys
- 연결 1,060회