Learn R Programming

openaiRtools (version 0.2.2)

upload_file: Upload a File (Convenience Function)

Description

Shortcut that creates an OpenAI client from the OPENAI_API_KEY environment variable and calls client$files$create().

Usage

upload_file(file, purpose)

Value

A file object with $id (the file ID), $status, $filename, $bytes, and other metadata.

Arguments

file

Character or raw. Required. Local file path or raw bytes.

purpose

Character. Required. Intended use of the file: "assistants", "vision", "batch", or "fine-tune".

Examples

Run this code
if (FALSE) {
Sys.setenv(OPENAI_API_KEY = "sk-xxxxxx")

# Upload training data for fine-tuning
file_obj <- upload_file("my_training_data.jsonl", purpose = "fine-tune")
cat("Uploaded file ID:", file_obj$id)

# Upload a document for an Assistant
file_obj <- upload_file("research_paper.pdf", purpose = "assistants")
cat("File ID:", file_obj$id)
}

Run the code above in your browser using DataLab