Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAI updated it's Python SDK, so updating FT script to reflect those changes #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions openai_finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,48 @@
import time

import openai
from openai import OpenAI

openai.api_key = os.getenv("OPENAI_API_KEY")
training_file = "/Users/juberti/Downloads/pirate_tune.jsonl"
training_file_response = openai.File.create(
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just do openai.OpenAI here rather than importing the type directly


training_file = "/Users/zachkoch/Downloads/GPT3_5_complete_fine_tuning_examples.jsonl"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get this from sys.argv[1]

training_file_response = client.files.create(
file=open(training_file, "rb"), purpose="fine-tune"
)
training_file_id = training_file_response["id"]
training_file_id = training_file_response.id
print(f"Training file uploaded with ID: {training_file_id}")

fine_tuning_job = openai.FineTuningJob.create(
training_file=training_file_id, model="gpt-3.5-turbo"
fine_tuning_job = client.fine_tuning.jobs.create(
training_file=training_file_id, model="gpt-3.5-turbo-1106"
)
job_id = fine_tuning_job["id"]
job_id = fine_tuning_job.id
print(f"Fine-tuning job created with ID: {job_id}")

while True:
try:
fine_tuning_status = openai.FineTune.retrieve(job_id)
except openai.error.InvalidRequestError as e:
fine_tuning_status = client.fine_tuning.jobs.retrieve(job_id)
except openai.InvalidRequestError as e:
print(e)
time.sleep(1)
continue

status = fine_tuning_status["status"]
status = fine_tuning_status.status
print(f"Fine-tuning job status: {status}")

if status in ["completed", "failed"]:
if status in ["succeeded", "failed"]:
break

time.sleep(60)
fine_tuned_model_id = fine_tuning_status["fine_tuned_model_id"]
fine_tuned_model_id = fine_tuning_status.fine_tuned_model

completion = openai.ChatCompletion.create(
completion = client.chat.completions.create(
model=fine_tuned_model_id,
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
{
"role": "system",
"content": "You are a helpful assistant.",
},
{"role": "user", "content": "What is 1/2 + 1/4?"},
],
)
print(completion.choices[0].message)