Module files

Source
Expand description

This module provides functionality for working with files using the OpenAI Files API.

Typical usage includes uploading a JSONL file for fine-tuning or other purposes, listing all files, retrieving file metadata, deleting a file, or even downloading its contents.

§Workflow

  1. Upload a file with upload_file (usually a .jsonl file for fine-tuning data).
  2. List files with list_files, which returns metadata for all uploaded files.
  3. Retrieve file metadata with retrieve_file_metadata for a specific file ID.
  4. Delete a file you no longer need with delete_file.
  5. Download file content with retrieve_file_content, if necessary for debugging or reuse.

§Example

use chat_gpt_lib_rs::api_resources::files::{upload_file, UploadFilePurpose};
use chat_gpt_lib_rs::OpenAIClient;
use chat_gpt_lib_rs::error::OpenAIError;
use std::path::PathBuf;

#[tokio::main]
async fn main() -> Result<(), OpenAIError> {
    let client = OpenAIClient::new(None)?;

    // Suppose you have a JSONL file at "./training_data.jsonl" for fine-tuning
    let file_path = PathBuf::from("./training_data.jsonl");

    // Upload the file with purpose "fine-tune"
    let file_obj = upload_file(&client, &file_path, UploadFilePurpose::FineTune).await?;
    println!("Uploaded file ID: {}", file_obj.id);

    Ok(())
}

Structs§

DeleteFileResponse
Represents the response returned by the Delete File endpoint.
FileListResponse
A response type for listing files. Contains an array of FileObject.
FileObject
Represents a file object in OpenAI.

Enums§

UploadFilePurpose
The “purpose” parameter you must supply when uploading a file.

Functions§

delete_file
Deletes a file by its ID.
list_files
Lists all files stored in your OpenAI account.
retrieve_file_content
Downloads the content of a file by its ID.
retrieve_file_metadata
Retrieves metadata about a specific file by its ID.
upload_file
Uploads a file to OpenAI.