Reputation: 21
I work with Python in Jupyter Notebook 7.0.8 :
Here is the error generated by the following cell:
The error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[10], line 5
2 dataset_path = r"*****"
4 # Fine-tune the model with the examples from the dataset
----> 5 fine_tuned_model_id = fine_tune_model_with_examples(dataset_path)
6 print(f"Fine-tuned model ID: {fine_tuned_model_id}")
8 # Example source code to analyze
Cell In[9], line 34, in fine_tune_model_with_examples(dataset_path)
26 # Launch fine-tuning
27 fine_tuning_parameters = {
28 "training_file": train_file_id,
29 "validation_file": test_file_id,
30 "model": "gpt-3.5-turbo",
31 "n_epochs": 4
32 }
---> 34 response = client.fine_tunes.create(**fine_tuning_parameters)
35 return response['id']
AttributeError: 'OpenAI' object has no attribute 'fine_tunes'
The cell causing the error:
# Function to fine-tune the model
def fine_tune_model_with_examples(dataset_path):
# Load and balance the dataset
balanced_dataset = load_and_balance_dataset(dataset_path)
# Split the dataset into training and test sets
train_set, test_set = split_dataset(balanced_dataset)
# Prepare fine-tuning data in chat format
train_examples = prepare_fine_tuning_data(train_set)
test_examples = prepare_fine_tuning_data(test_set)
# Save training and test data to JSONL files
save_to_jsonl(train_examples, "train_fine_tuning_data.jsonl")
save_to_jsonl(test_examples, "test_fine_tuning_data.jsonl")
# Upload training and test data to OpenAI
with open("train_fine_tuning_data.jsonl", 'rb') as train_file:
train_file_response = client.files.create(file=train_file, purpose='fine-tune')
with open("test_fine_tuning_data.jsonl", 'rb') as test_file:
test_file_response = client.files.create(file=test_file, purpose='fine-tune')
train_file_id = train_file_response.id
test_file_id = test_file_response.id
# Launch fine-tuning
fine_tuning_parameters = {
"training_file": train_file_id,
"validation_file": test_file_id,
"model": "gpt-3.5-turbo",
"n_epochs": 4
}
response = client.fine_tunes.create(**fine_tuning_parameters)
return response['id']
I made sure to update all the packages used.
However, it is indicated (https://github.com/openai/openai-python/discussions/742) among the changes made with the update of the OpenAI API that: openai.FineTune.create() is now client.fine_tunes.create().
Does anyone have a solution to suggest to me?
Thank you in advance ;)
Upvotes: 1
Views: 315
Reputation: 21
I was able to solve the issue by replacing the portion of code that was no longer compatible with API V1:
# Upload training and test data to OpenAI
with open("*****.jsonl", 'rb') as train_file:
train_file_response = client.files.create(file=train_file, purpose='fine-tune')
Thank you for the help.
Upvotes: 0