Fine tunning model issues

Please translate the text to English: “I’m having trouble running fine-tuning on a custom model… I’ve generated several Python programs but they always give an error, and ChatGPT can’t help me due to the fact that the API has undergone modifications after 2020. Would it be possible for someone to help me by analyzing the code that has the following goal: upload a file, train the model in ‘tex-davinci-003’ mode so I can access it in the playground. I will copy the code I used (which is not working) for your evaluation and suggestions. Thank you in advance, Helvio.”

import openai
import os

Define a function for training

def train_openai_gpt(file_id):
# Authenticate the API Key
openai.api_key = “XXXX”

# Define the model name

model_name = “text-davinci-003”

# Configure the training parameters

training_config = {
"model": "gpt-3.5-turbo",
"training_file": [file_id], # Replace with your actual file ID
"validation_file": your_validation_file_id, # Replace with your actual validation file ID
# Add other configurations if needed

}

training_config = {

“model”: model_name,

“datasets”: [file_id],

“n_epochs”: 5,

“learning_rate_multiplier”: 5e-5,

“batch_size”: 1,

“prompt_tokens”: [“Assistente”],

“temperature”: 0.5,

}

# Start the training
response = openai.FineTune.create(**training_config)
model_output = response["model_output"]

return model_output

Load the file for training

def upload_file(file_path):
# Authenticate the API Key
openai.api_key = “xx”

# Define the file name
file_name = os.path.basename(file_path)

# Upload the file to OpenAI
response = openai.File.create(file=open(file_path, "rb"), purpose="fine-tune")

# Return the file ID
return response["id"]

Define the file path

file_path = “train_model.jsonl”

Upload the file to OpenAI

file_id = upload_file(file_path)

Start the model training with the uploaded file

model_output = train_openai_gpt(file_id)

Display the model result

print(model_output)

end

Before we dive into the specifics of your issues, tell me what you’re trying to accomplish. Just a brief set of bullet points. I want to get a feel for why you believe a fine-tuned model is the right approach.

Also, @helviodarochalima, please edit your post and wrap your code with Markdown triple backticks because it’s very hard to read (it’s a mess, TBH),

Here is how to do it, note the Markdown triple backticks are on their own line, before and after the code, and your code goes between the backticks:

```
# your code here
```

Thank you

:slight_smile: