View Source ExOpenAI.Files (ex_openai.ex v1.7.0)

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. Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB.

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

Link to this function

create_file(file, purpose, opts \\ [])

View Source
@spec create_file(
  bitstring() | {String.t(), bitstring()},
  :vision | :"fine-tune" | :batch | :assistants,
  base_url: String.t(),
  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. Individual files can be up to 512 MB, and the size of all files uploaded by one organization can be up to 100 GB.

The Assistants API supports files up to 2 million tokens and of specific file types. See the Assistants Tools guide for details.

The Fine-tuning API only supports .jsonl files. The input also has certain required formats for fine-tuning chat or completions models.

The Batch API only supports .jsonl files up to 100 MB in size. The input also has a specific required format.

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 "assistants" for Assistants and Message files, "vision" for Assistants image file inputs, "batch" for Batch API, and "fine-tune" for Fine-tuning.

Optional Arguments:

  • openai_api_key: OpenAI API key to pass directly. If this is specified, it will override the api_key config value.

  • openai_organization_key: OpenAI API key to pass directly. If this is specified, it will override the organization_key config value.

  • base_url: Which API endpoint to use as base, defaults to https://api.openai.com/v1

Link to this function

delete_file(file_id, opts \\ [])

View Source
@spec delete_file(String.t(),
  base_url: 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 the api_key config value.

  • openai_organization_key: OpenAI API key to pass directly. If this is specified, it will override the organization_key config value.

  • base_url: Which API endpoint to use as base, defaults to https://api.openai.com/v1

Link to this function

download_file(file_id, opts \\ [])

View Source
@spec download_file(String.t(),
  base_url: 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 the api_key config value.

  • openai_organization_key: OpenAI API key to pass directly. If this is specified, it will override the organization_key config value.

  • base_url: Which API endpoint to use as base, defaults to https://api.openai.com/v1

@spec list_files(
  base_url: String.t(),
  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 to

  • purpose

  • openai_api_key: OpenAI API key to pass directly. If this is specified, it will override the api_key config value.

  • openai_organization_key: OpenAI API key to pass directly. If this is specified, it will override the organization_key config value.

  • base_url: Which API endpoint to use as base, defaults to https://api.openai.com/v1

Link to this function

retrieve_file(file_id, opts \\ [])

View Source
@spec retrieve_file(String.t(),
  base_url: 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 the api_key config value.

  • openai_organization_key: OpenAI API key to pass directly. If this is specified, it will override the organization_key config value.

  • base_url: Which API endpoint to use as base, defaults to https://api.openai.com/v1