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

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

QA

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

본문

1994226684_1699578400.4468.png

 

// 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

다음과 같이 해 볼 수 있을것 같습니다.


// 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
    );
    // 디버깅을 위해 요청과 응답 출력
    $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);
    $response = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Curl error: ' . curl_error($ch);
    }
    curl_close($ch);
    // 디버깅을 위해 응답 출력
    echo $response;
}

 

이렇게 하면 어디서 오류가 발생하는지 파악할 수 있으므로, 오류를 해결 할 수 있지 않을까 합니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 7
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1402호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT