챗gpt가 자동을 안하는데 어떻게 하면 좋을까요?? 채택완료

// 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 );
이부분이 작동을 안하는데 왜그럴까요 cf 값 넣어줬는데 안되네요
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
채택된 답변
+20 포인트
2년 전
다음과 같이 해 볼 수 있을것 같습니다.
</p>
<p>// CHATGPT 추가 시작
if ($chatgpt){ //CHATGPT 요청
$api_key = $config['cf_1'];
$url = "<a href="https://api.openai.com/v1/chat/completions";" target="_blank" rel="noopener noreferrer">https://api.openai.com/v1/chat/completions";</a></p>
<p> $post_fields = array(
"model" => "gpt-3.5-turbo",
"messages" => array(
array(
"role" => "user",
"content" => $wr_content
)
),
"max_tokens" => 4000,
"temperature" => 0
);</p>
<p> // 디버깅을 위해 요청과 응답 출력
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer ' . $api_key,
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);</p>
<p> $response = curl_exec($ch);</p>
<p> if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}</p>
<p> curl_close($ch);</p>
<p> // 디버깅을 위해 응답 출력
echo $response;
}
이렇게 하면 어디서 오류가 발생하는지 파악할 수 있으므로, 오류를 해결 할 수 있지 않을까 합니다.
로그인 후 평가할 수 있습니다
답변에 대한 댓글 2개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인전체 질문 목록
답변대기
답변대기
답변대기
답변대기
답변대기
답변대기
답변대기
답변대기
채택
답변대기
답변대기
답변대기
답변대기
채택
채택
답변대기
답변대기
답변대기
채택