gpt-4.1-2025-04-14· OpenAI
LMArena Human Preference 140K
Prepare it for openai
- User
Prepare it for openai
- Assistant
Prepare it for openai
Absolutely! Here’s a ready-to-use example for OpenAI’s fine-tuning and evaluation process, using the OpenAI fine-tuning format and a simple evaluation set.
Save this as acme_finetune.jsonl:
{"messages": [{"role": "system", "content": "You are a helpful customer support assistant for Acme Gadgets."}, {"role": "user", "content": "How do I reset my Acme Widget 3000?"}, {"role": "assistant", "content": "To reset your Acme Widget 3000, press and hold the power button for 10 seconds until the device restarts."}]}
{"messages": [{"role": "system", "content": "You are a helpful customer support assistant for Acme Gadgets."}, {"role": "user", "content": "What is the warranty period for Acme Widget 3000?"}, {"role": "assistant", "content": "The Acme Widget 3000 comes with a 2-year warranty from the date of purchase."}]}
{"messages": [{"role": "system", "content": "You are a helpful customer support assistant for Acme Gadgets."}, {"role": "user", "content": "Can I get a replacement if my device is not working?"}, {"role": "assistant", "content": "Yes, if your device is within the warranty period and meets our replacement criteria, you can request a replacement."}]}
{"messages": [{"role": "system", "content": "You are a helpful customer support assistant for Acme Gadgets."}, {"role": "user", "content": "Where can I download the user manual for Acme Widget 3000?"}, {"role": "assistant", "content": "You can download the user manual for the Acme Widget 3000 from our official website under the 'Support' section."}]}
Save this as acme_eval.jsonl:
{"messages": [{"role": "system", "content": "You are a helpful customer support assistant for Acme Gadgets."}, {"role": "user", "content": "How do I reset my Acme Widget 3000?"}], "expected_completion": "To reset your Acme Widget 3000, press and hold the power button for 10 seconds until the device restarts."}
{"messages": [{"role": "system", "content": "You are a helpful customer support assistant for Acme Gadgets."}, {"role": "user", "content": "What is the warranty period for Acme Widget 3000?"}], "expected_completion": "The Acme Widget 3000 comes with a 2-year warranty from the date of purchase."}
{"messages": [{"role": "system", "content": "You are a helpful customer support assistant for Acme Gadgets."}, {"role": "user", "content": "Can I get a replacement if my device is not working?"}], "expected_completion": "Yes, if your device is within the warranty period and meets our replacement criteria, you can request a replacement."}
{"messages": [{"role": "system", "content": "You are a helpful customer support assistant for Acme Gadgets."}, {"role": "user", "content": "Where can I download the user manual for Acme Widget 3000?"}], "expected_completion": "You can download the user manual for the Acme Widget 3000 from our official website under the 'Support' section."}
Upload your training file:
openai files create -p fine-tune -f acme_finetune.jsonl
Start fine-tuning:
openai fine_tuning.jobs.create -m gpt-3.5-turbo-0613 -t <TRAIN_FILE_ID>
OpenAI now supports custom evaluation via the OpenAI Evals framework, but you can also do a simple script-based check:
import openai
import json
# Load your evaluation set
with open("acme_eval.jsonl") as f:
eval_data = [json.loads(line) for line in f]
model = "ft:gpt-3.5-turbo-0613:your-org::your-job-id" # Replace with your fine-tuned model name
correct = 0
for item in eval_data:
response = openai.ChatCompletion.create(
model=model,
messages=item["messages"]
)
answer = response['choices'][0]['message']['content'].strip()
expected = item["expected_completion"].strip()
print(f"Q: {item['messages'][-1]['content']}")
print(f"Model: {answer}")
print(f"Expected: {expected}")
print("---")
if answer == expected:
correct += 1
print(f"Accuracy: {correct}/{len(eval_data)} = {correct/len(eval_data):.2%}")
You can now fine-tune and evaluate your model using these files and scripts, following OpenAI’s best practices!
Let me know if you need a more advanced example or want to see how to use OpenAI Evals for more robust evaluation.