View Source ExOpenAI.Files (ex_openai.ex v1.3.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 contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact us if you need to increase the storage limit.

Returns the contents of the specified file.

Functions

Link to this function

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

View Source
@spec create_file(bitstring() | {String.t(), bitstring()}, String.t(),
  openai_organization_key: String.t(),
  openai_api_key: String.t()
) :: {:ok, ExOpenAI.Components.OpenAIFile.t()} | {:error, any()}

Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact us if you need to increase the storage limit.

Endpoint: https://api.openai.com/v1/files

Method: POST

Docs: https://platform.openai.com/docs/api-reference/files


Required Arguments:

If the purpose is set to "fine-tune", the file will be used for fine-tuning. (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 documents.

Use "fine-tune" for fine-tuning. This allows us to validate the format of the uploaded file.

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.

Link to this function

delete_file(file_id, opts \\ [])

View Source
@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 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.

Link to this function

download_file(file_id, opts \\ [])

View Source
@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 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.