makeBCT

#AI #OpenAI #Chatbot #Cloud #WordPress

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 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

인기 글

사용자 작성 모듈 import 시 에러)(ModuleNotFoundError: No module named
파이썬 모듈을 만들고 테스트 할 때 ModuleNotFoundError: No module named 에러가 발생한 경우 원인 파이썬은 모듈을 불러올 때 모듈 설치 경로와 자신의...
오라클 클라우드 OCI 가입 드디어 성공 했습니다 (상세 후기)
2023년 2월 16일에 ‘오라클 클라우드 지급 검증 실패 글‘을 남긴 적이 있습니다. 그 때 검색을 통해 해결 방법을 찾아 보았고, 당시 성공했던 분들의...
Ubuntu 22.04 LTS에 Python 3.8 or 3.9 설치 방법
서버 : Vultr 클라우드OS: Ubuntu 22.04 LTS사용자 계정 생성하여 설치 진행함 1. Start with the system update sudo apt update...
Ubuntu 20.04에 MySQL 5.7 설치
비씨티원 인공지능 서비스 플랫폼 BAP(Bctone AI service Platform)의 설치 환경은 공식적으로 Ubuntu 18.04와 MySQL 버전 5.7 입니다. 최근 Ubuntu...
AWS 인스턴스 유형 변경 방법
AWS 인스턴스 유형을 변경하기 위한 방법에는 다음 2가지가 있습니다.   1. 첫 번째 방법 AMI 이미지 생성 후 해당 이미지를 복원하여 신규 EC2 인스턴스를 생성하는...

BCT Ai Chatbot

답변을 준비중입니다 . . .