Class: OpenAI::Resources::Uploads

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/resources/uploads.rb,
lib/openai/resources/uploads/parts.rb

Overview

Use Uploads to upload large files in multiple parts.

Defined Under Namespace

Classes: Parts

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Uploads

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Uploads.

Parameters:



129
130
131
132
# File 'lib/openai/resources/uploads.rb', line 129

def initialize(client:)
  @client = client
  @parts = OpenAI::Resources::Uploads::Parts.new(client: client)
end

Instance Attribute Details

#partsOpenAI::Resources::Uploads::Parts (readonly)

Use Uploads to upload large files in multiple parts.



9
10
11
# File 'lib/openai/resources/uploads.rb', line 9

def parts
  @parts
end

Instance Method Details

#cancel(upload_id, request_options: {}) ⇒ OpenAI::Models::Upload

Some parameter documentations has been truncated, see Models::UploadCancelParams for more details.

Cancels the Upload. No Parts may be added after an Upload is cancelled.

Returns the Upload object with status ‘cancelled`.

Parameters:

  • upload_id (String)

    The ID of the Upload.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



74
75
76
77
78
79
80
81
# File 'lib/openai/resources/uploads.rb', line 74

def cancel(upload_id, params = {})
  @client.request(
    method: :post,
    path: ["uploads/%1$s/cancel", upload_id],
    model: OpenAI::Upload,
    options: params[:request_options]
  )
end

#complete(upload_id, part_ids:, md5: nil, request_options: {}) ⇒ OpenAI::Models::Upload

Some parameter documentations has been truncated, see Models::UploadCompleteParams for more details.

Completes the [Upload](platform.openai.com/docs/api-reference/uploads/object).

Within the returned Upload object, there is a nested [File](platform.openai.com/docs/api-reference/files/object) object that is ready to use in the rest of the platform.

You can specify the order of the Parts by passing in an ordered list of the Part IDs.

The number of bytes uploaded upon completion must match the number of bytes initially specified when creating the Upload object. No Parts may be added after an Upload is completed. Returns the Upload object with status ‘completed`, including an additional `file` property containing the created usable File object.

Parameters:

  • upload_id (String)

    The ID of the Upload.

  • part_ids (Array<String>)

    The ordered list of Part IDs.

  • md5 (String)

    The optional md5 checksum for the file contents to verify if the bytes uploaded

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



115
116
117
118
119
120
121
122
123
124
# File 'lib/openai/resources/uploads.rb', line 115

def complete(upload_id, params)
  parsed, options = OpenAI::UploadCompleteParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["uploads/%1$s/complete", upload_id],
    body: parsed,
    model: OpenAI::Upload,
    options: options
  )
end

#create(bytes:, filename:, mime_type:, purpose:, expires_after: nil, request_options: {}) ⇒ OpenAI::Models::Upload

Some parameter documentations has been truncated, see Models::UploadCreateParams for more details.

Creates an intermediate [Upload](platform.openai.com/docs/api-reference/uploads/object) object that you can add [Parts](platform.openai.com/docs/api-reference/uploads/part-object) to. Currently, an Upload can accept at most 8 GB in total and expires after an hour after you create it.

Once you complete the Upload, we will create a [File](platform.openai.com/docs/api-reference/files/object) object that contains all the parts you uploaded. This File is usable in the rest of our platform as a regular File object.

For certain ‘purpose` values, the correct `mime_type` must be specified. Please refer to documentation for the [supported MIME types for your use case](platform.openai.com/docs/assistants/tools/file-search#supported-files).

For guidance on the proper filename extensions for each purpose, please follow the documentation on [creating a File](platform.openai.com/docs/api-reference/files/create).

Returns the Upload object with status ‘pending`.

Parameters:

  • bytes (Integer)

    The number of bytes in the file you are uploading.

  • filename (String)

    The name of the file to upload.

  • mime_type (String)

    The MIME type of the file.

  • purpose (Symbol, OpenAI::Models::FilePurpose)

    The intended purpose of the uploaded file.

  • expires_after (OpenAI::Models::UploadCreateParams::ExpiresAfter)

    The expiration policy for a file. By default, files with ‘purpose=batch` expire

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



53
54
55
56
# File 'lib/openai/resources/uploads.rb', line 53

def create(params)
  parsed, options = OpenAI::UploadCreateParams.dump_request(params)
  @client.request(method: :post, path: "uploads", body: parsed, model: OpenAI::Upload, options: options)
end