ChatGPT 달았어요,  그런데 응답을 한글로 했는데 깨져 보임이다.

ChatGPT 달았어요,  그런데 응답을 한글로 했는데 깨져 보임이다.

QA

ChatGPT 달았어요,  그런데 응답을 한글로 했는데 깨져 보임이다.

본문

ChatGPT 달았어요, 

그런데 질문 및 응답을 한글로 했는데 깨져 보임이다.

한글이 정상적으로 나오게 하려면 어떻게 해야하나요?

소스는 다음과 같습니다.

 

-----------------------------------------------------

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ChatGPT Form</title>
</head>
  <body>
    <form action="gpt-run.php" method="post">
      <div>
        <div><label for="prompt">prompt:</label></div>
        <textarea id="prompt" name="prompt" cols="40" rows="3" required><?php echo $_POST['prompt']; ?></textarea>
      </div>
      <div><?php echo $_POST['response']; ?></div>
      <div>
        <input type="submit" value="Submit">
      </div>
    </form>
    <script>
      document.getElementById("prompt").select();
    //   document.getElementById("prompt").focus();
    </script>
  </body>
</html>

 

-----------------------------------------------------

 

 

3661044743_1684803603.426.png

이 질문에 댓글 쓰기 :

답변 6

<head>
    <meta charset="UTF-8">

위의 부분에 하면 되나요?

위와 같이 했는데 한글이 깨지네요.

그리고 저장을 아래와 같이 => Unicode (UTF-8) 로 했습니다.

그러데도 한글이 깨짐니다. 

감사합니다.

3661044743_1684805178.4557.png

gpt-run.php 의 함수 코드에서 한글로 해야 하나요?

 

소스 코드

 

<?php

$api_key = "";

function translate($content, $source='ko', $target='en') {
    $handle = curl_init();
    curl_setopt($handle, CURLOPT_URL,'https://www.googleapis.com/language/translate/v2');
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
    $data = array('key' => "API Key",
                    'q' => $content,
                    'source' => $source,
                    'target' => $target);
    curl_setopt($handle, CURLOPT_POSTFIELDS, preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', http_build_query($data)));
    curl_setopt($handle,CURLOPT_HTTPHEADER,array('X-HTTP-Method-Override: GET'));
    $response = curl_exec($handle);
    $responseDecoded = json_decode($response, true);
    $responseCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
    curl_close($handle);
    return  $responseDecoded['data']['translations'][0]['translatedText'];
}

function ko2en($content) {
    return translate($content, 'ko', 'en');
}

function en2ko($content) {
    return translate($content, 'en', 'ko');
}

$url = "https://api.openai.com/v1/completions";

// "What is the capital of France?"
$prompt = filter_var($_POST["prompt"], FILTER_SANITIZE_STRING);;

$data = array(
    "model" => "text-davinci-003",  
    "prompt" => $prompt,
    "max_tokens" => 3000,
    "temperature" => 0.5,
);

$data_string = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Content-Type: application/json",
    "Authorization: Bearer $api_key",
    "Content-Length: " . strlen($data_string))
);

$output = curl_exec($ch);
curl_close($ch);
// print_r($output);

$output_json = json_decode($output, true);
$response = $output_json["choices"][0]["text"];

// echo $response;
?>
<form method="post" id="gpt-run" action="gpt-form.php" onsubmit="return true;" style="display:none;">
  <textarea id="response" name="response"><?php echo trim($response); ?></textarea>
  <textarea id="prompt" name="prompt"><?php echo $prompt; ?></textarea>
  <input type="submit" value="Submit">
</form>
<script>
    document.getElementById("gpt-run").submit();
</script>

 

 

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

회원로그인

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