Chatgpt에서 현재 제공하고 있는 언어모델은 범용적으로 학습된 모델로 데이터를 추가적으로 학습을 시켜 원하는 답변을 얻어 필요한 분야에 적용할 수 있다.
이를 위해 현재 적용할 목표의 Text들(Page등)을 가져와 openai에서 이해할 수 있는 training data로 가공을 합니다.
이렇게 가공된 training data를 이용해 OpenAI에서 제공하는 API를 이용해 튜닝된 언어 모델을 생성할 수 있습니다. (Fine-tuning)
2. 작업 절차
2.1 데이터 수집 및 가공
2.1.1 데이터 수집
목표로하고 있는 Data가 있는 서버 API를 이용해서 대상 페이지의 Text를 crawlling 할 수 있습니다. 아래는 컨플루언스 페이지 명을 읽어와 text를 파일(컨플페이지명_YYYYMMDDhhmmss.txt)로 남겨주는 Python 예제 코드입니다. → 이 코드도 chatgpt를 이용해 작성함.
import requests import json import datetime
# API 인증 토큰 생성 url = 'https://your-confluence-site.com/rest/api/user/token' username = 'your-username' password = 'your-password' response = requests.post(url, auth=(username, password)) token = json.loads(response.text)['token']
# 대상 페이지명 입력 받기 page_title = input("Enter page title: ")
# 페이지 ID 확인 url = f" https://your-confluence-site.com/rest/api/content?title= {page_title}&expand=history" headers = { "Authorization": f"Bearer {token}", "Content-Type": "application/json" } response = requests.get(url, headers=headers) page_id = json.loads(response.text)['results'][0]['id']
# 페이지 내용에서 텍스트 추출 from bs4 import BeautifulSoup soup = BeautifulSoup(page_content, 'html.parser') text = soup.get_text()
# 결과를 파일로 저장 now = datetime.datetime.now() filename = f"{page_title}_{now.strftime('%Y%m%d%H%M%S')}.txt" with open(filename, "w", encoding="utf-8") as f: f.write(text)
print(f"Result saved to {filename}")
이렇게 수집된 text 데이터를 가지고 chatgpt에서 이해하고 학습할 수 있는 데이터 셋을 jsonl 형식으로 가공을 해야 합니다.
2.1.2 데이터 가공
Fine-tuning을 위한 training data set은 JSONL 형태로 남겨야 합니다.