2. Fine-tuning the model
To train the model, we retrieve our training file and create a fine-tuning job. We begin by creating an OpenAI client:
from openai import OpenAI
import jsonlines
client = OpenAI()
Then we use the file we generated to create another training file that is uploaded to OpenAI:
# Uploading the training file
result_file = client.files.create(
file=open("QA_prompts_and_completions.json", "rb"),
purpose="fine-tune"
)
We print the file information for the dataset we are going to use for fine-tuning:
print(result_file)
param_training_file_name = result_file.id
print(param_training_file_name)
We now create and display the fine-tuning job:
# Creating the fine-tuning job
ft_job = client.fine_tuning.jobs.create(
training_file=param_training_file_name,
model="gpt-4o-mini-2024-07-18"
)
# Printing the fine-tuning job
print(ft_job)
The output first provides the name of the file, its purpose...