Noizu.OpenAI.Api.File (Noizu Labs: OpenAI v0.1.3)

Noizu.OpenAI.Api.File is a module that provides functionality for managing files using OpenAI's API.

This module offers several functions for file management:

  1. list/1 - Lists all the files.
  2. info/2 - Retrieves information about a specific file.
  3. fetch/2 - Fetches the content of a specific file.
  4. create/2 - Creates a new file with the given file and options.
  5. delete/2 - Deletes a specific file.

usage

Usage

{:ok, files} = Noizu.OpenAI.Api.File.list(options)
{:ok, file_info} = Noizu.OpenAI.Api.File.info(file, options)
{:ok, file_content} = Noizu.OpenAI.Api.File.fetch(file, options)
{:ok, new_file} = Noizu.OpenAI.Api.File.create(file, options)
{:ok, deleted_file} = Noizu.OpenAI.Api.File.delete(file, options)

Link to this section Summary

Functions

Uploads a file to OpenAI's API for use in various features like fine-tuning.

Deletes a file from the OpenAI API.

Retrieves the content of a specific file by its ID from the OpenAI API.

Fetches a list of files from the OpenAI API.

Fetches a list of files from the OpenAI API.

Link to this section Types

Link to this type

delete_file_options()

@type delete_file_options() :: Noizu.OpenAI.stream_options()
Link to this type

delete_file_response()

@type delete_file_response() :: map()
Link to this type

file_info_options()

@type file_info_options() :: Noizu.OpenAI.stream_options()
Link to this type

file_info_response()

@type file_info_response() :: map()
Link to this type

file_options()

@type file_options() :: Noizu.OpenAI.stream_options()
Link to this type

file_response()

@type file_response() :: map()
Link to this type

files_options()

@type files_options() :: Noizu.OpenAI.stream_options()
Link to this type

files_response()

@type files_response() :: map()
Link to this type

upload_file_options()

@type upload_file_options() ::
  %{
    optional(:purpose) => Noizu.OpenAI.purpose_option(),
    optional(:stream) => Noizu.OpenAI.stream_option()
  }
  | Keyword.t()
Link to this type

upload_file_response()

@type upload_file_response() :: map()

Link to this section Functions

Link to this function

create(file, options \\ nil)

@spec create(file :: String.t(), options :: upload_file_options()) ::
  {:ok, upload_file_response()} | {:error, term()}

Uploads a file to OpenAI's API for use in various features like fine-tuning.

parameters

Parameters

  • file: The URL of the file to be uploaded
  • options: A keyword list or map containing optional parameters
    • :purpose (String.t()): The purpose of the uploaded file (e.g., "fine-tuning")
    • :stream (boolean): A boolean value to indicate whether the request should be processed as a stream or not (default: false)

returns

Returns

Returns a tuple {:ok, upload_file_response()} on successful file upload, where upload_file_response() is a map containing the response data. Returns {:error, term} on failure, where term contains error details.

example

Example

file_url = "https://example.com/my_file.txt"
options = [purpose: "fine-tuning"]
{:ok, response} = Noizu.OpenAI.upload_file(file_url, options)
Link to this function

delete(file, options \\ nil)

@spec delete(file :: String.t(), delete_file_options()) ::
  {:ok, delete_file_response()} | {:error, term()}

Deletes a file from the OpenAI API.

parameters

Parameters

  • file: The ID of the file to be deleted
  • options: An optional keyword list or map containing stream options

returns

Returns

Returns a tuple {:ok, delete_file_response()} on successful file deletion. Returns {:error, term} on failure, where term contains error details.

example

Example

file_id = "your_file_id_here"
{:ok, response} = Noizu.OpenAI.delete_file(file_id)
Link to this function

fetch(file, options \\ nil)

@spec fetch(file :: String.t(), file_options()) ::
  {:ok, file_response()} | {:error, term()}

Retrieves the content of a specific file by its ID from the OpenAI API.

parameters

Parameters

  • file: The ID of the file to retrieve content from
  • options: Optional keyword list or map containing stream options

returns

Returns

Returns a tuple {:ok, file_response()} on success, where file_response() is a map containing file content. Returns {:error, term} on failure, where term contains error details.

Link to this function

info(file, options \\ nil)

@spec info(file_id :: String.t(), file_info_options()) ::
  {:ok, file_info_response()} | {:error, term()}

Fetches a list of files from the OpenAI API.

parameters

Parameters

  • options: A map or keyword list of options, such as stream (for streaming API calls)

returns

Returns

Returns a tuple {:ok, response} on successful retrieval, where response is a map containing the list of files. Returns {:error, term} on failure, where term contains error details.

example

Example

{:ok, response} = Noizu.OpenAI.Api.File.info()
Link to this function

list(options \\ nil)

@spec list(files_options()) :: {:ok, files_response()} | {:error, term()}

Fetches a list of files from the OpenAI API.

parameters

Parameters

  • options: A map or keyword list of options, such as stream (for streaming API calls)

returns

Returns

Returns a tuple {:ok, response} on successful retrieval, where response is a map containing the list of files. Returns {:error, term} on failure, where term contains error details.

example

Example

{:ok, response} = Noizu.OpenAI.Api.File.list()