View Source ExOpenAI.Files (ex_openai.ex v1.5.1)
Modules for interacting with the files
group of OpenAI APIs
API Reference: https://platform.openai.com/docs/api-reference/files
Summary
Functions
Upload a file that can be used across various endpoints/features. The size of all the files uploaded by one organization can be up to 100 GB.
Delete a file.
Returns the contents of the specified file.
Returns a list of files that belong to the user's organization.
Returns information about a specific file.
Functions
@spec create_file(bitstring() | {String.t(), bitstring()}, :assistants | :"fine-tune", openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, ExOpenAI.Components.OpenAIFile.t()} | {:error, any()}
Upload a file that can be used across various endpoints/features. The size of all the files uploaded by one organization can be up to 100 GB.
The size of individual files for can be a maximum of 512MB. See the Assistants Tools guide to learn more about the types of files supported. The Fine-tuning API only supports .jsonl
files.
Please contact us if you need to increase these storage limits.
Endpoint: https://api.openai.com/v1/files
Method: POST
Docs: https://platform.openai.com/docs/api-reference/files
Required Arguments:
file
: The File object (not file name) to be uploaded. (Pass in a file object created with something like File.open!, or a {filename, file object} tuple to preserve the filename information, eg{"filename.ext", File.open!("/tmp/file.ext")}
)purpose
: The intended purpose of the uploaded file.
Use "fine-tune" for Fine-tuning and "assistants" for Assistants and Messages. This allows us to validate the format of the uploaded file is correct for fine-tuning.
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.
@spec delete_file(String.t(), openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, ExOpenAI.Components.DeleteFileResponse.t()} | {:error, any()}
Delete a file.
Endpoint: https://api.openai.com/v1/files/{file_id}
Method: DELETE
Docs: https://platform.openai.com/docs/api-reference/files
Required Arguments:
file_id
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.
@spec download_file(String.t(), openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, String.t()} | {:error, any()}
Returns the contents of the specified file.
Endpoint: https://api.openai.com/v1/files/{file_id}/content
Method: GET
Docs: https://platform.openai.com/docs/api-reference/files
Required Arguments:
file_id
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.
@spec list_files( openai_organization_key: String.t(), openai_api_key: String.t(), purpose: String.t(), stream_to: (... -> any()) | pid() ) :: {:ok, ExOpenAI.Components.ListFilesResponse.t()} | {:error, any()}
Returns a list of files that belong to the user's organization.
Endpoint: https://api.openai.com/v1/files
Method: GET
Docs: https://platform.openai.com/docs/api-reference/files
Required Arguments:
Optional Arguments:
stream_to
: PID or function of where to stream content topurpose
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.
@spec retrieve_file(String.t(), openai_organization_key: String.t(), openai_api_key: String.t() ) :: {:ok, ExOpenAI.Components.OpenAIFile.t()} | {:error, any()}
Returns information about a specific file.
Endpoint: https://api.openai.com/v1/files/{file_id}
Method: GET
Docs: https://platform.openai.com/docs/api-reference/files
Required Arguments:
file_id
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.