import json
from openai import OpenAI

# we can use gpt-4o-mini , gpt-4o or gpt-3.5-turbo . right now we use mini for price reason
gpt_model = "gpt-4o-mini"
openai_api_key = "apikey"

fine_tune_modelname = "mensa-hsai"


def train_gpt(data):
    client = OpenAI(api_key=openai_api_key)
    training_temp_filename = "training.jsonl"

    # create files that contain training data in jsonl format
    with open(training_temp_filename, 'w') as file:
        for entry in data:
            json.dump(entry, file)
            file.write('\n')

    # upload file training to gpt
    training_file = client.files.create(
        file=open(training_temp_filename, 'rb'), purpose='fine-tune')
    print("Training file id:", training_file.id)

    # create job to start training
    response = client.fine_tuning.jobs.create(
        training_file=training_file.id,
        model=gpt_model,
        suffix=fine_tune_modelname
    )

    print("GPT Fine Tune job id:", response.id)





