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.jsonl
file for fine-tuning data). - List files with
list_files
, which returns metadata for all uploaded files. - Retrieve file metadata with
retrieve_file_metadata
for 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§
- Delete
File Response - Represents the response returned by the Delete File endpoint.
- File
List Response - A response type for listing files. Contains an array of
FileObject
. - File
Object - Represents a file object in OpenAI.
Enums§
- Upload
File 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.