Issues with Implementing Fine-Tuned Model using Python Script

Hello Community,

I’ve successfully fine-tuned a model and I’m trying to implement it using a Python script. I’ve followed all the guidelines from the OpenAI documentation, but I’m encountering issues when I try to run the script.

Here are the steps I’ve taken:

Reading the Literature Review and Fine-Tuning Dataset: The script successfully reads my literature review and fine-tuning dataset.
Format Validation: No format errors were found in the dataset.
API Call: I’m using openai.ChatCompletion.create() to call the fine-tuned model.
The problems arise here. The script throws the following errors:

The model ‘ft:gpt-3.5-turbo:my-org:custom_suffix:id’ does not exist - Even though the fine-tuning job was successful.
Invalid API Key - I’ve triple-checked the API key, and it’s correct.
Module ‘openai’ has no attribute ‘Error’ - When I try to catch exceptions.
Here’s a simplified version of the script for reference:

python
Copy code

… (code to read and validate dataset)

… (code to set up logging)

try:
response = openai.ChatCompletion.create(
model=“ft:gpt-3.5-turbo:my-org:custom_suffix:id”, # Note: This is a placeholder
messages=[
{“role”: “system”, “content”: “You are an academic writing assistant.”},
{“role”: “user”, “content”: “Please review my literature.”},
# … (other messages)
]
)
except openai.Error as e: # This line throws an AttributeError
logging.error(f"OpenAI API error: {e}")

… (rest of the code)

Has anyone encountered similar issues or have any insights on what I might be doing wrong?

Thank you in advance for your help!

The API call certainly can’t work with just placeholder text. You have to get the model name that was assigned.

Get its name and if it is available in your account’s model list:

import openai
openai.api_key = "sk-xxx"

try:
	models = openai.Model.list()
	model_ids = [model.id for model in models["data"]]
	print(model_ids)
	# self.update_finished.emit(model_ids)
except Exception as err:
	print(f"Error updating model list: {err}")
1 Like

Hey champ!

The important part of the code that triggers the error is this:

You have to replace the custom_suffix:id with name and I’d of your fine tune, you can list your fine tunes with this bit of python

# List 10 fine-tuning jobs
openai.FineTuningJob.list(limit=10)

Hope that helps :heart:

3 Likes