I am attempting to train a custom model on a dataset. I can upload the file successfully, giving me a file ID. However, on the very next line in the command prompt I am met with this error: An error occurred while creating the fine-tuning job: ‘FineTuning’ object has no attribute ‘create’.
This is the part of the code I believe is relevant:
def create_fine_tuning_job(file_id, model="davinci"):
try:
fine_tune_response = client.fine_tuning.create(training_file=file_id,
model=model)
fine_tune_id = fine_tune_response.id
print(f"Fine-tuning job ID: {fine_tune_id}")
return fine_tune_id
except Exception as e:
print(f"An error occurred while creating the fine-tuning job: {e}")
return None
This is the entirety of my file:
from openai import OpenAI
client = OpenAI(api_key='my-api-key')
def upload_file(file_path):
try:
with open(file_path, "rb") as file:
file_response = client.files.create(file=file,
purpose="fine-tune")
file_id = file_response.id
print(f"Uploaded file ID: {file_id}")
return file_id
except Exception as e:
print(f"An error occurred while uploading the file: {e}")
return None
def create_fine_tuning_job(file_id, model="davinci"):
try:
fine_tune_response = client.fine_tuning.create(training_file=file_id,
model=model)
fine_tune_id = fine_tune_response.id
print(f"Fine-tuning job ID: {fine_tune_id}")
return fine_tune_id
except Exception as e:
print(f"An error occurred while creating the fine-tuning job: {e}")
return None
def monitor_fine_tuning(fine_tune_id):
try:
status = client.fine_tuning.retrieve(id=fine_tune_id)
print(f"Fine-tuning job status: {status.status}")
return status
except Exception as e:
print(f"An error occurred while monitoring the job: {e}")
return None
def get_fine_tuned_model_id(fine_tune_id):
try:
result = client.fine_tuning.retrieve(id=fine_tune_id)
fine_tuned_model_id = result.fine_tuned_model
print(f"Fine-tuned model ID: {fine_tuned_model_id}")
return fine_tuned_model_id
except Exception as e:
print(f"An error occurred while retrieving the model ID: {e}")
return None
if __name__ == "__main__":
file_path = "dataset.jsonl"
file_id = upload_file(file_path)
if file_id:
fine_tune_id = create_fine_tuning_job(file_id)
if fine_tune_id:
monitor_fine_tuning(fine_tune_id)
get_fine_tuned_model_id(fine_tune_id)
Any help is greatly appreciated.