Upload a file

Please follow to the fireworks file upload guide for more details.

Create a fine-tuning job

from portkey_ai import Portkey

# Initialize the Portkey client

portkey = Portkey(
    api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
    virtual_key="VIRTUAL_KEY", # Add your provider's virtual key
    fireworks_account_id="FIREWORKS_ACCOUNT_ID" # Add your fireworks's account id
)

fine_tune_job = portkey.fine_tuning.jobs.create(
    training_file="file_id",
    model="model_id",
    hyperparameters={
        "n_epochs": 1
    },
    validation_file="file_id",
    suffix="finetuned_model_name",
  )

print(fine_tune_job)

List Fine-tuning Jobs

from portkey_ai import Portkey

# Initialize the Portkey client
portkey = Portkey(
    api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
    virtual_key="VIRTUAL_KEY", # Add your provider's virtual key
    fireworks_account_id="FIREWORKS_ACCOUNT_ID" # Add your fireworks's account id
)

# List all fine-tuning jobs
jobs = portkey.fine_tuning.jobs.list(
    limit=10  # Optional: Number of jobs to retrieve (default: 20)
)

print(jobs)

Retrieve Fine-tuning Job

from portkey_ai import Portkey

# Initialize the Portkey client
portkey = Portkey(
    api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
    virtual_key="VIRTUAL_KEY", # Add your provider's virtual key
    fireworks_account_id="FIREWORKS_ACCOUNT_ID" # Add your fireworks's account id
)

# Retrieve a specific fine-tuning job
job = portkey.fine_tuning.jobs.retrieve(
    job_id="job_id"  # The ID of the fine-tuning job to retrieve
)

print(job)

Cancel Fine-tuning Job

from portkey_ai import Portkey

# Initialize the Portkey client
portkey = Portkey(
    api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
    virtual_key="VIRTUAL_KEY", # Add your provider's virtual key
    fireworks_account_id="FIREWORKS_ACCOUNT_ID" # Add your fireworks's account id
)

# Cancel a fine-tuning job
cancelled_job = portkey.fine_tuning.jobs.cancel(
    job_id="job_id"  # The ID of the fine-tuning job to cancel
)

print(cancelled_job)

References

Was this page helpful?