Expand description
This module provides functionality for working with fine-tuning jobs using the OpenAI Fine-tunes API.
Fine-tuning allows you to train a model on custom data so it can better handle domain-specific terminology or style. You start by uploading training data as a file, and optionally a validation file. Then you create a fine-tune job pointing to those files. Once the job is finished, you can use the resulting fine-tuned model for completions or other tasks.
§Overview
- Upload training file (outside the scope of this module, see the Files API).
- Create a fine-tune job with
create_fine_tune. - List fine-tunes with
list_fine_tunes. - Retrieve a fine-tune with
retrieve_fine_tune. - Cancel a fine-tune with
cancel_fine_tune, if needed. - List fine-tune events with
list_fine_tune_events(to see training progress). - Delete fine-tuned model with
delete_fine_tune_model, if you want to remove it.
§Example
use chat_gpt_lib_rs::api_resources::fine_tunes::{create_fine_tune, CreateFineTuneRequest};
use chat_gpt_lib_rs::error::OpenAIError;
use chat_gpt_lib_rs::OpenAIClient;
#[tokio::main]
async fn main() -> Result<(), OpenAIError> {
let client = OpenAIClient::new(None)?; // Reads API key from OPENAI_API_KEY
// Create a fine-tune job (assumes you've already uploaded a file and obtained its ID).
let request = CreateFineTuneRequest {
training_file: "file-abc123".to_string(),
model: Some("curie".to_string()),
..Default::default()
};
let response = create_fine_tune(&client, &request).await?;
println!("Created fine-tune: {}", response.id);
Ok(())
}Structs§
- Create
Fine Tune Request - A request struct for creating a fine-tune job.
- Delete
Fine Tune Model Response - Response returned after deleting a fine-tuned model.
- Fine
Tune - Represents a fine-tune job, either newly created or retrieved from the API.
- Fine
Tune Event - Represents a single event in a fine-tune job’s lifecycle (e.g., job enqueued, model trained).
- Fine
Tune Events List - A helper struct for deserializing the result of
GET /v1/fine-tunes/{fine_tune_id}/events. - Fine
Tune List - The response for listing fine-tunes: an object with
"data"containing an array ofFineTune.
Functions§
- cancel_
fine_ tune - Cancels a fine-tune job by its ID.
- create_
fine_ tune - Creates a fine-tune job.
- delete_
fine_ tune_ model - Deletes a fine-tuned model (i.e., the actual model generated after successful fine-tuning).
- list_
fine_ tune_ events - Lists events for a given fine-tune job (useful for seeing training progress).
- list_
fine_ tunes - Lists all fine-tune jobs associated with the user’s API key.
- retrieve_
fine_ tune - Retrieves a fine-tune job by its ID (e.g. “ft-XXXXXXXX”).