OpenAI의 데이터 요구사항
OpenAI는 chat-messages 포맷의 JSONL을 요구. 최소 10개 예제(50~100+ 추천), 최대 파일 크기 1GB. 시스템 메시지는 예제 가로질러 일관되거나 완전히 생략.
업로드 전 validator
업로드 전에 파일 검증해. OpenAI API가 잘못된 파일은 거절하지만, 로컬 검증이 더 빠르고 읽기 쉬운 에러 메시지 줘.
~22 min · openai, jsonl, upload, validation
OpenAI는 chat-messages 포맷의 JSONL을 요구. 최소 10개 예제(50~100+ 추천), 최대 파일 크기 1GB. 시스템 메시지는 예제 가로질러 일관되거나 완전히 생략.
업로드 전에 파일 검증해. OpenAI API가 잘못된 파일은 거절하지만, 로컬 검증이 더 빠르고 읽기 쉬운 에러 메시지 줘.
from openai import OpenAI
import json
client = OpenAI()
def validate_openai_data(filepath: str) -> int:
"""Returns number of valid examples; raises on hard errors."""
with open(filepath) as f:
data = [json.loads(line) for line in f]
print(f"Number of examples: {len(data)}")
if len(data) < 10:
raise ValueError(f"Too few examples: {len(data)} < 10")
for i, ex in enumerate(data):
msgs = ex.get("messages", [])
if not msgs:
raise ValueError(f"Example {i}: missing 'messages'")
if msgs[-1]["role"] != "assistant":
raise ValueError(f"Example {i}: last message must be assistant")
for j, m in enumerate(msgs):
if not (m.get("content") or "").strip():
raise ValueError(f"Example {i} msg {j}: empty content")
chars = sum(len(json.dumps(ex)) for ex in data)
tokens = chars // 4
print(f"Estimated tokens: ~{tokens:,}")
print(f"Estimated training cost on gpt-4.1-mini @ 3 epochs: "
f"~${tokens * 3 / 1_000_000 * 0.80:.2f}")
return len(data)
validate_openai_data("training_data.jsonl")
# Upload after local validation passes
training_file = client.files.create(
file=open("training_data.jsonl", "rb"),
purpose="fine-tune",
)
print(f"File ID: {training_file.id}")
# Optional but recommended: validation file for monitoring
validation_file = client.files.create(
file=open("validation_data.jsonl", "rb"),
purpose="fine-tune",
)
print(f"Validation File ID: {validation_file.id}")아직 댓글이 없어요. 첫 댓글을 남겨보세요.