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
- Upload a file with upload_file(usually a.jsonlfile for fine-tuning data).
- List files with list_files, which returns metadata for all uploaded files.
- Retrieve file metadata with retrieve_file_metadatafor a specific file ID.
- Delete a file you no longer need with delete_file.
- 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§
- DeleteFile Response 
- Represents the response returned by the Delete File endpoint.
- FileList Response 
- A response type for listing files. Contains an array of FileObject.
- FileObject 
- Represents a file object in OpenAI.
Enums§
- UploadFile Purpose 
- 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.