Hello,
I’ve created a project in my account, I’m the account owner. I’ve created an API key related to this account and I’m the only user of it. By default, this API key has all the permissions and as I’m the owner I also have all the permissions.
I’ve trained 3 FT models yesterday and reached my quota. But I can’t delete any of the models.
client.models.delete(my_model_id)
PermissionDeniedError: Error code: 403 - {'error': {'message': "You have insufficient permissions for this operation. Missing scopes: api.delete. Check that you have the correct role in your organization (Owner), and if you're using a restricted API key, that it has the necessary scopes.", 'type': 'server_error', 'param': None, 'code': None}}
I don’t understand the problem as I have all permissions set but it looks like there is a problem with the api.delete which may come from the fact that it’s an api from a project created. I tried with the old API but I get a ModelNotFoundError
and can’t train new one as I’ve reached the quota.
Here is the code I fine tune the model with, maybe it comes from this.
class OpenAIFineTuner:
"""
Class to fine tune OpenAI models
"""
def __init__(self, training_file_path, model_name, suffix):
self.training_file_path = training_file_path
self.model_name = model_name
self.suffix = suffix
self.file_object = None
self.fine_tuning_job = None
self.model_id = None
def create_openai_file(self):
self.file_object = client.files.create(
file=open(self.training_file_path, "rb"),
purpose="fine-tune",
)
def wait_for_file_processing(self, sleep_time=20):
while self.file_object.status != 'processed':
time.sleep(sleep_time)
self.file_object.refresh()
print("File Status: ", self.file_object.status)
def create_fine_tuning_job(self):
self.fine_tuning_job = client.fine_tuning.jobs.create(
training_file=self.file_object.id,
model=self.model_name,
suffix=self.suffix,
)
def wait_for_fine_tuning(self, sleep_time=45):
while self.fine_tuning_job.status != 'succeeded':
time.sleep(sleep_time)
self.fine_tuning_job = client.fine_tuning.jobs.retrieve(self.fine_tuning_job.id)
print("Job Status: ", self.fine_tuning_job.status)
def retrieve_fine_tuned_model(self):
self.model_id = client.fine_tuning.jobs.retrieve(self.fine_tuning_job.id).fine_tuned_model
return self.model_id
def fine_tune_model(self):
self.create_openai_file()
self.wait_for_file_processing()
self.create_fine_tuning_job()
self.wait_for_fine_tuning()
return self.retrieve_fine_tuned_model()
fine_tuner = OpenAIFineTuner(
training_file_path=join(path_data, f"{n}_industry_stratified.jsonl"),
model_name="gpt-3.5-turbo",
suffix=f"{n}_strat_20240507"
)
Any idea ?
Cheers,
Arnault