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

Migrating to v1: How to create a fine-tuning job and stream using async client? #1154

Open
1 task done
Pythonic-Rainbow opened this issue Feb 14, 2024 · 0 comments
Open
1 task done
Assignees

Comments

@Pythonic-Rainbow
Copy link

Pythonic-Rainbow commented Feb 14, 2024

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

In v0, astream_events is able to iterate and wait until the model is actually completed.

I've migrated it to v1 (see snippets), but fine_tuning.jobs.list_events() doesn't wait until the model is actually completed. The messages also seem to be in the reverse order.

I know that this is because it's not streaming, but I don't see a method or parameter (e.g. stream=True) that allows me to stream and wait for the events.

To Reproduce

  1. Use AsyncClient
  2. await fine tuning job create
  3. try to stream and wait for all events

Code snippets

# v0 - works
with open('ai_data/model.jsonl', 'rb') as f:
            upload_resp = await openai.File.acreate(f, 'fine-tune')
file_id = upload_resp.id
tune_resp = await openai.FineTune.acreate(training_file=file_id, model='babbage')
async for event in await openai.FineTune.astream_events(tune_resp.id):
    print(event.message)
print('Completed. New Model ID: ' + tune_resp.fine_tuned_model)

# v1
with open('ai_data/model.jsonl', 'rb') as f:
    upload_resp = await client.files.create(file=f, purpose='fine-tune')
file_id = upload_resp.id
tune_resp = await client.fine_tuning.jobs.create(training_file=file_id, model='babbage-002')
async for event in client.fine_tuning.jobs.list_events(tune_resp.id):
    print(event.message)
# Only prints the following
# Sending model train request
# Validating training file: file-XZpR8yio1o1Hw7wPyxfRXtYQ
# Created fine-tuning job: ftjob-f9UuWfBcOOu3Vhd0jR3k65oa

print('Completed. New Model ID: ' + tune_resp.fine_tuned_model) # Error because the model is not completed yet

OS

Windows

Python version

3.11.5

Library version

1.10.6

@Pythonic-Rainbow Pythonic-Rainbow added the bug Something isn't working label Feb 14, 2024
@rattrayalex rattrayalex removed the bug Something isn't working label Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants