Class: OpenAI::Resources::Uploads

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

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:



119
120
121
122
# File 'lib/openai/resources/uploads.rb', line 119

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

Instance Attribute Details

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



7
8
9
# File 'lib/openai/resources/uploads.rb', line 7

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.

Parameters:

  • upload_id (String)

    The ID of the Upload.

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

Returns:

See Also:



66
67
68
69
70
71
72
73
# File 'lib/openai/resources/uploads.rb', line 66

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.

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:



105
106
107
108
109
110
111
112
113
114
# File 'lib/openai/resources/uploads.rb', line 105

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: , 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).

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.

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

Returns:

See Also:



47
48
49
50
# File 'lib/openai/resources/uploads.rb', line 47

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