Reputation: 23
this is my first openAI fine-tuning job so I don't know much. I am trying to fine-tune OpenAI API to generate product ID based on the description. The code runs successfully and also generates model ID, I also got billed for it. However, when I want to use to the model to generate output it gives NotFoundError: Error code: 404 - {'error': {'message': 'The model `ftjob-****' does not exist or you do not have access to it.', 'type': 'invalid_request_error', 'param': None, 'code': 'model_not_found'}}
My complete code is given below.
import pandas as pd
df = pd.read_csv("/content/machine screws.csv")
df.head()
def convert_to_gpt35_format(dataset):
fine_tuning_data = []
for _, row in dataset.iterrows():
fine_tuning_data.append({
"messages": [
{"role": "user", "content": row['Input']},
{"role": "assistant", "content": row['Output']} #json_response}
]
})
return fine_tuning_data
converted_data = convert_to_gpt35_format(df)
from sklearn.model_selection import train_test_split
train_data, val_data = train_test_split(
converted_data,
test_size=0.2,
random_state=42 # for reproducibility
)
import json
def write_to_jsonl(data, file_path):
with open(file_path, 'w') as file:
for entry in data:
json.dump(entry, file)
file.write('\n')
training_file_name = "train_a.jsonl"
validation_file_name = "val_a.jsonl"
write_to_jsonl(train_data, training_file_name)
write_to_jsonl(val_data, validation_file_name)
from openai import OpenAI
client = OpenAI(api_key="OPENAI_KEY")
training_file = client.files.create(
file=open(training_file_name, "rb"), purpose="fine-tune"
)
validation_file = client.files.create(
file=open(validation_file_name, "rb"), purpose="fine-tune"
)
response = client.fine_tuning.jobs.create(
training_file=training_file.id,
validation_file=validation_file.id,
model="gpt-3.5-turbo",
)
print("Fine-Tuning Job ID:", response.id)
print("Status:", response.status)
print("Created at:", response.created_at)
job_id = response.id
prompt = " 1-8 X 15 FLAT SLTD MACH SCREW 3 THRD HDG "
response = client.chat.completions.create(
model=job_id, messages=prompt, temperature=0, max_tokens=50
)
prediction_text = response.choices[0].text.strip()
print(f"Predicted code: {prediction_text}")
Upvotes: 1
Views: 289
Reputation: 11391
You need to specify the api_version
found here
You also need to specify the azure_endpoint which you will find in "resources and keys" in the azure portal.
from openai import AzureOpenAI
client = AzureOpenAI(
api_version="2024-02-01",
api_key=os.environ.get("OPENAI_KEY"),
azure_endpoint="https://your-deployment.openai.azure.com"
)
Also with your model the naming convention is slightly different and you will need to be more specific with the version:
model="gpt-35-turbo-0125",
Upvotes: 0