Skip to content

Commit

Permalink
fix: update code to latest version of openai
Browse files Browse the repository at this point in the history
  • Loading branch information
nsantacruz committed Jun 17, 2024
1 parent 67c64c1 commit 13b6833
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/util/fine_tune/create_fine_tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _get_file_ids():
def create_fine_tune_job(model: str, suffix: str):
training_file_id, validation_file_id = _get_file_ids()

fine_tuning_job = openai.FineTuningJob.create(
fine_tuning_job = openai.fine_tuning.jobs.create(
model=model,
training_file=training_file_id,
validation_file=validation_file_id,
Expand All @@ -24,14 +24,14 @@ def create_fine_tune_job(model: str, suffix: str):
}
)

return fine_tuning_job["id"]
return fine_tuning_job.id


def monitor_fine_tune_job(job_id):
import time

while True:
fine_tuning_status = openai.FineTune.get_status(job_id)
fine_tuning_status = openai.fine_tuning.jobs.retrieve(job_id)
status = fine_tuning_status["status"]
print(f"Fine-tuning job status: {status}")

Expand Down
2 changes: 1 addition & 1 deletion app/util/fine_tune/fine_tune_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def fine_tune(output_file: str):
openai.api_key = os.getenv("OPENAI_API_KEY")
fine_tune_jobs = openai.FineTuningJob.list()['data']
fine_tune_jobs = openai.fine_tuning.jobs.list()['data']
last_job = max(fine_tune_jobs, key=lambda x: x.created_at)
results_file_id = last_job['result_files'][0]
content = openai.File.download(results_file_id)
Expand Down
2 changes: 1 addition & 1 deletion app/util/fine_tune/fine_tune_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
openai.api_key = os.getenv("OPENAI_API_KEY")

def fine_tune_status(output_file: str):
fine_tune_jobs = openai.FineTuningJob.list()['data']
fine_tune_jobs = list(openai.fine_tuning.jobs.list())
last_job = max(fine_tune_jobs, key=lambda x: x.created_at)
last_job_dict = last_job.to_dict()
print(last_job_dict)
Expand Down
7 changes: 4 additions & 3 deletions app/util/fine_tune/upload_fine_tune_files.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import typer
import json
from openai import File
from openai import OpenAI


def upload_files(training_filename: str, validation_filename: str):
training_file = File.create(file=open(training_filename, "r"), purpose='fine-tune')
validation_file = File.create(file=open(validation_filename, "r"), purpose='fine-tune')
client = OpenAI()
training_file = client.files.create(file=open(training_filename, "rb"), purpose='fine-tune')
validation_file = client.files.create(file=open(validation_filename, "rb"), purpose='fine-tune')
out = {
"training_file_id": training_file.id,
"validation_file_id": validation_file.id
Expand Down

0 comments on commit 13b6833

Please sign in to comment.