2023년 October 4일
  1. AI 트레이닝 센터
  2. BCT AI 솔루션
  3. BCT AI Chatbot
  4. BCT AI Chatbot 0.6 버전에 GPT3.5를 활용한 개발...

BCT AI Chatbot 0.6 버전에 GPT3.5를 활용한 개발 코드 추가

BCT AI Chatbot 0.6 버전에서 기존 GPT3 기반의 Fine-tune 모델을 GPT3.5-turbo 모델로 업그레이드 하면서 Dataset에도 변화가 생겼습니다. 기존 jsonl 포맷인 prompt-completion 대신 chat-completion 을 따라야 하는데, 당연히 새로운 포맷의 chat-completion format을 다루기 위한 코드에도 변화가 생기게 되었습니다. 그래서 이 문제를 GPT3에게 물어서 해결하고자 했고, 그 결과는 아주 좋았습니다.

먼저, chat-completion format 샘플 코드는 다음과 같았습니다.

lists.push({"messages":[{role: "system", content: item_system }, {role: "user", content: item_user }, {role: "assistant", content: item_assistant }]}) 

이 코드를 다음과 같이 php 코드로 변환해 달라고 요청 하였습니다.

이 코드를 php로 변환해줘
<?php
// 기존의 배열
$lists = [];

// 새로운 메시지 객체를 생성하여 배열에 추가
$newMessage = [
    "messages" => [
        ["role" => "system", "content" => $item_system],
        ["role" => "user", "content" => $item_user],
        ["role" => "assistant", "content" => $item_assistant]
    ]
];

// 배열에 새로운 메시지 객체를 추가
array_push($lists, $newMessage);

// 결과 확인
print_r($lists);
?>

GPT3.5가 추천해 준 위 코드를 BCT AI Chatbot에 추가하여 테스트 해 보니, 원하는 결과가 잘 나왔습니다.

[{"messages":[{"role":"system","content":"BCTONE is a system chat"},{"role":"user","content":"\uae30\uc5c5\uba85"},{"role":"assistant","content":"Country: \uad6d\uac00, Company Name: \uae30\uc5c5\uba85, Company Address: \uae30\uc5c5\uc8fc\uc18c, Zip Code: \uc6b0\ud3b8 \ubc88\ud638, Industry Group: \uc0b0\uc5c5\uad70, Featured Products: \uc8fc\uc694 \uc81c\ud488\/\uc11c\ube44\uc2a4 \ud3ec\ud2b8\ud3f4\ub9ac\uc624, Phone: \ub2f4\ub2f9\uc790 \ud734\ub300\ud3f0 \ubc88\ud638, Tel: \uae30\uc5c5 \uc804\ud654 \ubc88\ud638, Fax: \ud329\uc2a4 \ubc88\ud638, Website: \uc6f9\uc0ac\uc774\ud2b8, Email: \uc774\uba54\uc77c, Recent News: \ucd5c\uc2e0 \ub274\uc2a4, Equity Relationship: \uc9c0\ubd84 \uad00\uacc4\ub3c4, Stock Related Information: \uc8fc\uc2dd \uad00\ub828 \uc815\ubcf4, Business Registration: \uc0ac\uc5c5\uc790 \ub4f1\ub85d\uc99d, Listing Date: \uc0c1\uc7a5\uc77c\uc790 \ub4f1, "}]}]

그런데 Fine-tune을 해 보니 전체를 감싸고 있는 [] 가 문제이었고, 이 []를 제거해 달라고 다음과 같이 요청하였습니다.

처음 대괄호와 마지막 대괄호 대괄호 쌍을 제거하고 남은 문자열을 출력하려면?

$jsonString = '[{"messages":[{"role":"system","content":"BCTONE is a system chat"},{"role":"user","content":"\uae30\uc5c5\uba85"},{"role":"assistant","content":"Country: \uad6d\uac00, Company Name: \uae30\uc5c5\uba85, Company Address: \uae30\uc5c5\uc8fc\uc18c, Zip Code: \uc6b0\ud3b8 \ubc88\ud638, Industry Group: \uc0b0\uc5c5\uad70, Featured Products: \uc8fc\uc694 \uc81c\ud488\/\uc11c\ube44\uc2a4 \ud3ec\ud2b8\ud3f4\ub9ac\uc624, Phone: \ub2f4\ub2f9\uc790 \ud734\ub300\ud3f0 \ubc88\ud638, Tel: \uae30\uc5c5 \uc804\ud654 \ubc88\ud638, Fax: \ud329\uc2a4 \ubc88\ud638, Website: \uc6f9\uc0ac\uc774\ud2b8, Email: \uc774\uba54\uc77c, Recent News: \ucd5c\uc2e0 \ub274\uc2a4, Equity Relationship: \uc9c0\ubd84 \uad00\uacc4\ub3c4, Stock Related Information: \uc8fc\uc2dd \uad00\ub828 \uc815\ubcf4, Business Registration: \uc0ac\uc5c5\uc790 \ub4f1\ub85d\uc99d, Listing Date: \uc0c1\uc7a5\uc77c\uc790 \ub4f1, "}]}]';

// 처음 대괄호와 마지막 대괄호 쌍을 제거하고 나머지 문자열 출력
$trimmedString = substr($jsonString, 1, -1);

echo $trimmedString;

물론 실제 적용 시에는 코드 수정을 약간 했지만, 이 정도만 해도 충분히 원하는 코드를 만들어 주는 것을 확인할 수 있었습니다.

Leave a Reply

Your email address will not be published. Required fields are marked *

연관 글
BCT NEWS
인기 글
워드프레스 유지보수
워드프레스 제작 팁
클라우드
워드프레스 유지보수