View Source ExOpenAI.Assistants (ex_openai.ex v1.5.1)

Modules for interacting with the assistants group of OpenAI APIs

API Reference: https://platform.openai.com/docs/api-reference/assistants

Summary

Functions

Create an assistant with a model and instructions.

Create an assistant file by attaching a File to an assistant.

Retrieves an assistant.

Returns a list of assistant files.

Returns a list of assistants.

Functions

Link to this function

create_assistant(model, opts \\ [])

View Source
@spec create_assistant(String.t(),
  openai_organization_key: String.t(),
  openai_api_key: String.t(),
  tools: [map()],
  name: String.t(),
  metadata: map(),
  instructions: String.t(),
  file_ids: [String.t()],
  description: String.t(),
  stream_to: (... -> any()) | pid()
) :: {:ok, ExOpenAI.Components.AssistantObject.t()} | {:error, any()}

Create an assistant with a model and instructions.

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

Method: POST

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


Required Arguments:

  • model: ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them.

Optional Arguments:

  • stream_to: PID or function of where to stream content to

  • description: The description of the assistant. The maximum length is 512 characters.

  • file_ids: A list of file IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. Files are ordered by their creation date in ascending order.

  • instructions: The system instructions that the assistant uses. The maximum length is 32768 characters.

  • metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long.

  • name: The name of the assistant. The maximum length is 256 characters.

  • tools: A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types code_interpreter, retrieval, or function.

  • 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

create_assistant_file(assistant_id, file_id, opts \\ [])

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

Create an assistant file by attaching a File to an assistant.

Endpoint: https://api.openai.com/v1/assistants/{assistant_id}/files

Method: POST

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


Required Arguments:

  • assistant_id

Example: file-AF1WoRqd3aJAHsqc9NY7iL8F

  • file_id: A File ID (with purpose="assistants") that the assistant should use. Useful for tools like retrieval and code_interpreter that can access files.

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_assistant(assistant_id, opts \\ [])

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

Delete an assistant.

Endpoint: https://api.openai.com/v1/assistants/{assistant_id}

Method: DELETE

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


Required Arguments:

  • assistant_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

delete_assistant_file(assistant_id, file_id, opts \\ [])

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

Delete an assistant file.

Endpoint: https://api.openai.com/v1/assistants/{assistant_id}/files/{file_id}

Method: DELETE

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


Required Arguments:

  • assistant_id

  • 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

get_assistant(assistant_id, opts \\ [])

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

Retrieves an assistant.

Endpoint: https://api.openai.com/v1/assistants/{assistant_id}

Method: GET

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


Required Arguments:

  • assistant_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

get_assistant_file(assistant_id, file_id, opts \\ [])

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

Retrieves an AssistantFile.

Endpoint: https://api.openai.com/v1/assistants/{assistant_id}/files/{file_id}

Method: GET

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


Required Arguments:

  • assistant_id

  • 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

list_assistant_files(assistant_id, opts \\ [])

View Source
@spec list_assistant_files(String.t(),
  openai_organization_key: String.t(),
  openai_api_key: String.t(),
  before: String.t(),
  after: String.t(),
  order: String.t(),
  limit: integer(),
  stream_to: (... -> any()) | pid()
) :: {:ok, ExOpenAI.Components.ListAssistantFilesResponse.t()} | {:error, any()}

Returns a list of assistant files.

Endpoint: https://api.openai.com/v1/assistants/{assistant_id}/files

Method: GET

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


Required Arguments:

  • assistant_id

Optional Arguments:

  • stream_to: PID or function of where to stream content to

  • limit

  • order

  • after

  • before

  • 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

list_assistants(opts \\ [])

View Source
@spec list_assistants(
  openai_organization_key: String.t(),
  openai_api_key: String.t(),
  before: String.t(),
  after: String.t(),
  order: String.t(),
  limit: integer(),
  stream_to: (... -> any()) | pid()
) :: {:ok, ExOpenAI.Components.ListAssistantsResponse.t()} | {:error, any()}

Returns a list of assistants.

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

Method: GET

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


Required Arguments:

Optional Arguments:

  • stream_to: PID or function of where to stream content to

  • limit

  • order

  • after

  • before

  • 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

modify_assistant(assistant_id, opts \\ [])

View Source
@spec modify_assistant(String.t(),
  openai_organization_key: String.t(),
  openai_api_key: String.t(),
  tools: [map()],
  name: String.t(),
  model: String.t(),
  metadata: map(),
  instructions: String.t(),
  file_ids: [String.t()],
  description: String.t(),
  stream_to: (... -> any()) | pid()
) :: {:ok, ExOpenAI.Components.AssistantObject.t()} | {:error, any()}

Modifies an assistant.

Endpoint: https://api.openai.com/v1/assistants/{assistant_id}

Method: POST

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


Required Arguments:

  • assistant_id

Optional Arguments:

  • stream_to: PID or function of where to stream content to

  • description: The description of the assistant. The maximum length is 512 characters.

  • file_ids: A list of File IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. Files are ordered by their creation date in ascending order. If a file was previosuly attached to the list but does not show up in the list, it will be deleted from the assistant.

  • instructions: The system instructions that the assistant uses. The maximum length is 32768 characters.

  • metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long.

  • model: ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them.

  • name: The name of the assistant. The maximum length is 256 characters.

  • tools: A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types code_interpreter, retrieval, or function.

  • 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.