Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Run llama Llama index OpenAIFinetuneEngine Get Current Job

From Leeroopedia

Overview

The get_current_job method on OpenAIFinetuneEngine retrieves the latest status of the finetuning job from the OpenAI API. It returns the full FineTuningJob object from the OpenAI Python SDK, enabling callers to check job status, access the finetuned model ID, and inspect training metadata.

Source File

  • File: llama-index-finetuning/llama_index/finetuning/openai/base.py
  • Lines: 94-102
  • Import: Accessed as a method on OpenAIFinetuneEngine instances

Method Signature

def get_current_job(self) -> FineTuningJob:
    """Get current job."""

Parameters: None (instance method)

Returns: FineTuningJob -- An OpenAI FineTuningJob object (from openai.types.fine_tuning)

Raises: ValueError -- If finetune() has not been called and no start_job_id was provided to the constructor

Implementation Detail

def get_current_job(self) -> FineTuningJob:
    """Get current job."""
    # validate that it works
    if not self._start_job:
        raise ValueError("Must call finetune() first")

    # try getting id, make sure that run succeeded
    job_id = self._start_job.id
    return self._client.fine_tuning.jobs.retrieve(job_id)

The method performs two operations:

  1. Validation: Checks that self._start_job is populated (either from finetune() or from the start_job_id constructor parameter). If not, raises a descriptive error.
  2. API retrieval: Extracts the job ID from the stored job object and calls client.fine_tuning.jobs.retrieve(job_id) to get the latest state from the OpenAI API. This is important because the stored self._start_job reflects the state at creation time, while retrieve() returns the current state.

Return Value: FineTuningJob

The returned FineTuningJob object contains these key attributes:

Attribute Type Description
id str Unique job identifier (e.g., "ftjob-abc123")
status str One of: "validating_files", "queued", "running", "succeeded", "failed", "cancelled"
fine_tuned_model Optional[str] Model ID when status is "succeeded"; None otherwise
model str The base model being finetuned
created_at int Unix timestamp of job creation
finished_at Optional[int] Unix timestamp of job completion (if terminal)
trained_tokens Optional[int] Total tokens processed during training
error Optional[Error] Error details if the job failed

Usage Example

from llama_index.finetuning import OpenAIFinetuneEngine

# After launching a finetuning job
engine = OpenAIFinetuneEngine(
    base_model="gpt-3.5-turbo",
    data_path="training_data.jsonl",
)
engine.finetune()

# Check status
job = engine.get_current_job()
print(f"Job ID: {job.id}")
print(f"Status: {job.status}")
print(f"Model: {job.fine_tuned_model}")

# Or reconnect to an existing job
engine = OpenAIFinetuneEngine(
    base_model="gpt-3.5-turbo",
    data_path="training_data.jsonl",
    start_job_id="ftjob-abc123",
)
job = engine.get_current_job()
print(f"Status: {job.status}")

# Polling loop
import time
while job.status not in ("succeeded", "failed", "cancelled"):
    time.sleep(60)
    job = engine.get_current_job()
    print(f"Status: {job.status}")

Knowledge Sources

Metadata

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment