Files
Create a file
Creates a file from the supplied request.
Cuerpo de la solicitud
The multipart request body.
file
OpenAI.CreateFileRequest
requerido
The File object (not file name) to be uploaded.
purpose
OpenAI.CreateFileRequest
requerido
The intended purpose of the uploaded file. One of: - assistants: Used in the Assistants API - batch: Used in the Batch API - fine-tune: Used for fine-tuning - vision: Images used for vision fine-tuning - user_data: Flexible file type for any purpose - evals: Used for eval data sets
expires_after
OpenAI.FileExpirationAfter
The expiration policy for a file. By default, files with purpose=batch expire after 30 days and all other files are persisted until they are manually deleted.
anchor
enum
requerido
Anchor timestamp after which the expiration policy applies. Supported anchors: created_at.
seconds
integer
requerido
The number of seconds after the anchor time that the file will expire. Must be between 3600 (1 hour) and 2592000 (30 days).
Respuestas
The request has succeeded.
Cuerpo
id
string
requerido
The file identifier, which can be referenced in the API endpoints.
bytes
integer | null
requerido
The size of the file, in bytes. In a completed file upload response, this can be null when the file size is not yet available.
created_at
integer
requerido
The Unix timestamp (in seconds) for when the file was created.
expires_at
integer
The Unix timestamp (in seconds) for when the file will expire. In a completed file upload response, this can be null when no expiry is set.
filename
string
requerido
The name of the file.
object
enum
requerido
The object type, which is always file.
purpose
enum
requerido
The intended purpose of the file. Supported values are assistants, assistants_output, batch, batch_output, fine-tune, fine-tune-results, vision, and user_data.
status
enum
requerido
Deprecated. The current status of the file, which can be either uploaded, processed, or error.
status_details
string
Deprecated. For details on why a fine-tuning training file failed validation, see the error field on fine_tuning.job. Completed file upload responses can return null when these details are unset.
Solicitar
curl https://api.openai.com/v1/files \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-F purpose="fine-tune" \
-F file="@mydata.jsonl"
-F expires_after[anchor]="created_at"
-F expires_after[seconds]=2592000
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
file_object = client.files.create(
file=b"Example data",
purpose="assistants",
)
print(file_object.id)
import fs from "fs";
import OpenAI from "openai";
const openai = new OpenAI();
async function main() {
const file = await openai.files.create({
file: fs.createReadStream("mydata.jsonl"),
purpose: "fine-tune",
expires_after: {
anchor: "created_at",
seconds: 2592000
}
});
console.log(file);
}
main();
import fs from 'fs';
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});
const fileObject = await client.files.create({
file: fs.createReadStream('fine-tune.jsonl'),
purpose: 'assistants',
});
console.log(fileObject.id);
package main
import (
"bytes"
"context"
"fmt"
"io"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
client := openai.NewClient(
option.WithAPIKey("My API Key"),
)
fileObject, err := client.Files.New(context.TODO(), openai.FileNewParams{
File: io.Reader(bytes.NewBuffer([]byte("Example data"))),
Purpose: openai.FilePurposeAssistants,
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v
", fileObject.ID)
}
package com.openai.example;
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.files.FileCreateParams;
import com.openai.models.files.FileObject;
import com.openai.models.files.FilePurpose;
import java.io.ByteArrayInputStream;
public final class Main {
private Main() {}
public static void main(String[] args) {
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
FileCreateParams params = FileCreateParams.builder()
.file(new ByteArrayInputStream("Example data".getBytes()))
.purpose(FilePurpose.ASSISTANTS)
.build();
FileObject fileObject = client.files().create(params);
}
}
require "openai"
openai = OpenAI::Client.new(api_key: "My API Key")
file_object = openai.files.create(file: StringIO.new("Example data"), purpose: :assistants)
puts(file_object)
Respuesta
{
"id": "file-abc123",
"object": "file",
"bytes": 120000,
"created_at": 1677610602,
"expires_at": 1677614202,
"filename": "mydata.jsonl",
"purpose": "fine-tune",
}