View Source ExOpenAI.Uploads (ex_openai.ex v1.8.0)
Modules for interacting with the uploads
group of OpenAI APIs
API Reference: https://platform.openai.com/docs/api-reference/uploads
Summary
Functions
@spec add_upload_part(String.t(), bitstring() | {String.t(), bitstring()}, base_url: String.t(), openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, ExOpenAI.Components.UploadPart.t()} | {:error, any()}
Adds a Part to an Upload object. A Part represents a chunk of bytes from the file you are trying to upload.
Each Part can be at most 64 MB, and you can add Parts until you hit the Upload maximum of 8 GB.
It is possible to add multiple Parts in parallel. You can decide the intended order of the Parts when you complete the Upload.
Endpoint: https://api.openai.com/v1/uploads/{upload_id}/parts
Method: POST
Docs: https://platform.openai.com/docs/api-reference/uploads
Required Arguments:
upload_id
Example: upload_abc123
data
: The chunk of bytes for this Part.
Optional Arguments:
openai_api_key
: "OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value."openai_organization_key
: "OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value."base_url
: "Which API endpoint to use as base, defaults to https://api.openai.com/v1"
@spec cancel_upload(String.t(), base_url: String.t(), openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, ExOpenAI.Components.Upload.t()} | {:error, any()}
Cancels the Upload. No Parts may be added after an Upload is cancelled.
Endpoint: https://api.openai.com/v1/uploads/{upload_id}/cancel
Method: POST
Docs: https://platform.openai.com/docs/api-reference/uploads
Required Arguments:
upload_id
Example: upload_abc123
Optional Arguments:
openai_api_key
: "OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value."openai_organization_key
: "OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value."base_url
: "Which API endpoint to use as base, defaults to https://api.openai.com/v1"
@spec complete_upload( String.t(), [String.t()], base_url: String.t(), openai_organization_key: String.t(), openai_api_key: String.t(), md5: String.t(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.Upload.t()} | {:error, any()}
Completes the Upload.
Within the returned Upload object, there is a nested File 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.
Endpoint: https://api.openai.com/v1/uploads/{upload_id}/complete
Method: POST
Docs: https://platform.openai.com/docs/api-reference/uploads
Required Arguments:
upload_id
Example: upload_abc123
part_ids
: The ordered list of Part IDs.
Optional Arguments:
stream_to
: "PID or function of where to stream content to"md5
: "The optional md5 checksum for the file contents to verify if the bytes uploaded matches what you expect.\n"openai_api_key
: "OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value."openai_organization_key
: "OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value."base_url
: "Which API endpoint to use as base, defaults to https://api.openai.com/v1"
@spec create_upload( integer(), String.t(), String.t(), :vision | :"fine-tune" | :batch | :assistants, base_url: String.t(), openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, ExOpenAI.Components.Upload.t()} | {:error, any()}
Creates an intermediate Upload object that you can add Parts 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 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.
For guidance on the proper filename extensions for each purpose, please follow the documentation on creating a File.
Endpoint: https://api.openai.com/v1/uploads
Method: POST
Docs: https://platform.openai.com/docs/api-reference/uploads
Required Arguments:
bytes
: The number of bytes in the file you are uploading.filename
: The name of the file to upload.mime_type
: The MIME type of the file.
This must fall within the supported MIME types for your file purpose. See the supported MIME types for assistants and vision.
purpose
: The intended purpose of the uploaded file.
See the documentation on File purposes.
Optional Arguments:
openai_api_key
: "OpenAI API key to pass directly. If this is specified, it will override theapi_key
config value."openai_organization_key
: "OpenAI API key to pass directly. If this is specified, it will override theorganization_key
config value."base_url
: "Which API endpoint to use as base, defaults to https://api.openai.com/v1"