View Source OpenAi.Assistants (OpenAI REST API Client v1.0.0)

Provides API endpoints related to assistants

Summary

Functions

Cancels a run that is in_progress.

Create an assistant with a model and instructions.

Create a thread and run it in one request.

Retrieves an assistant.

Retrieves a thread.

Returns a list of assistants.

Returns a list of messages for a given thread.

Returns a list of run steps belonging to a run.

Returns a list of runs belonging to a thread.

When a run has the status: "requires_action" and required_action.type is submit_tool_outputs, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request.

Functions

Link to this function

cancel_run(thread_id, run_id, opts \\ [])

View Source
@spec cancel_run(thread_id :: String.t(), run_id :: String.t(), opts :: keyword()) ::
  {:ok, OpenAi.Run.t()} | {:error, OpenAi.Error.error()}

Cancels a run that is in_progress.

Link to this function

create_assistant(body, opts \\ [])

View Source
@spec create_assistant(body :: OpenAi.Assistant.CreateRequest.t(), opts :: keyword()) ::
  {:ok, OpenAi.Assistant.t()} | {:error, OpenAi.Error.error()}

Create an assistant with a model and instructions.

Link to this function

create_message(thread_id, body, opts \\ [])

View Source
@spec create_message(
  thread_id :: String.t(),
  body :: OpenAi.Message.CreateRequest.t(),
  opts :: keyword()
) :: {:ok, OpenAi.Message.t()} | {:error, OpenAi.Error.error()}

Create a message.

Link to this function

create_run(thread_id, body, opts \\ [])

View Source
@spec create_run(
  thread_id :: String.t(),
  body :: OpenAi.Run.CreateRequest.t(),
  opts :: keyword()
) ::
  {:ok, OpenAi.Run.t()} | {:error, OpenAi.Error.error()}

Create a run.

Options

  • include[]: A list of additional fields to include in the response. Currently the only supported value is step_details.tool_calls[*].file_search.results[*].content to fetch the file search result content.

    See the file search tool documentation for more information.

Link to this function

create_thread(body, opts \\ [])

View Source
@spec create_thread(body :: OpenAi.Thread.CreateRequest.t(), opts :: keyword()) ::
  {:ok, OpenAi.Thread.t()} | {:error, OpenAi.Error.error()}

Create a thread.

Link to this function

create_thread_and_run(body, opts \\ [])

View Source
@spec create_thread_and_run(
  body :: OpenAi.Thread.CreateAndRunRequest.t(),
  opts :: keyword()
) ::
  {:ok, OpenAi.Run.t()} | {:error, OpenAi.Error.error()}

Create a thread and run it in one request.

Link to this function

delete_assistant(assistant_id, opts \\ [])

View Source
@spec delete_assistant(assistant_id :: String.t(), opts :: keyword()) ::
  {:ok, OpenAi.Assistant.DeleteResponse.t()} | {:error, OpenAi.Error.error()}

Delete an assistant.

Link to this function

delete_message(thread_id, message_id, opts \\ [])

View Source
@spec delete_message(
  thread_id :: String.t(),
  message_id :: String.t(),
  opts :: keyword()
) ::
  {:ok, OpenAi.Message.DeleteResponse.t()} | {:error, OpenAi.Error.error()}

Deletes a message.

Link to this function

delete_thread(thread_id, opts \\ [])

View Source
@spec delete_thread(thread_id :: String.t(), opts :: keyword()) ::
  {:ok, OpenAi.Thread.DeleteResponse.t()} | {:error, OpenAi.Error.error()}

Delete a thread.

Link to this function

get_assistant(assistant_id, opts \\ [])

View Source
@spec get_assistant(assistant_id :: String.t(), opts :: keyword()) ::
  {:ok, OpenAi.Assistant.t()} | {:error, OpenAi.Error.error()}

Retrieves an assistant.

Link to this function

get_message(thread_id, message_id, opts \\ [])

View Source
@spec get_message(
  thread_id :: String.t(),
  message_id :: String.t(),
  opts :: keyword()
) ::
  {:ok, OpenAi.Message.t()} | {:error, OpenAi.Error.error()}

Retrieve a message.

Link to this function

get_run(thread_id, run_id, opts \\ [])

View Source
@spec get_run(thread_id :: String.t(), run_id :: String.t(), opts :: keyword()) ::
  {:ok, OpenAi.Run.t()} | {:error, OpenAi.Error.error()}

Retrieves a run.

Link to this function

get_run_step(thread_id, run_id, step_id, opts \\ [])

View Source
@spec get_run_step(
  thread_id :: String.t(),
  run_id :: String.t(),
  step_id :: String.t(),
  opts :: keyword()
) :: {:ok, OpenAi.Run.Step.t()} | {:error, OpenAi.Error.error()}

Retrieves a run step.

Options

  • include[]: A list of additional fields to include in the response. Currently the only supported value is step_details.tool_calls[*].file_search.results[*].content to fetch the file search result content.

    See the file search tool documentation for more information.

Link to this function

get_thread(thread_id, opts \\ [])

View Source
@spec get_thread(thread_id :: String.t(), opts :: keyword()) ::
  {:ok, OpenAi.Thread.t()} | {:error, OpenAi.Error.error()}

Retrieves a thread.

Link to this function

list_assistants(opts \\ [])

View Source
@spec list_assistants(opts :: keyword()) ::
  {:ok, OpenAi.Assistant.ListResponse.t()} | {:error, OpenAi.Error.error()}

Returns a list of assistants.

Options

  • limit: A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

  • order: Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

  • after: A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

  • before: A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.

Link to this function

list_messages(thread_id, opts \\ [])

View Source
@spec list_messages(thread_id :: String.t(), opts :: keyword()) ::
  {:ok, OpenAi.Message.ListResponse.t()} | {:error, OpenAi.Error.error()}

Returns a list of messages for a given thread.

Options

  • limit: A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

  • order: Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

  • after: A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

  • before: A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.

  • run_id: Filter messages by the run ID that generated them.

Link to this function

list_run_steps(thread_id, run_id, opts \\ [])

View Source
@spec list_run_steps(thread_id :: String.t(), run_id :: String.t(), opts :: keyword()) ::
  {:ok, OpenAi.Run.Step.ListResponse.t()} | {:error, OpenAi.Error.error()}

Returns a list of run steps belonging to a run.

Options

  • limit: A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

  • order: Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

  • after: A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

  • before: A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.

  • include[]: A list of additional fields to include in the response. Currently the only supported value is step_details.tool_calls[*].file_search.results[*].content to fetch the file search result content.

    See the file search tool documentation for more information.

Link to this function

list_runs(thread_id, opts \\ [])

View Source
@spec list_runs(thread_id :: String.t(), opts :: keyword()) ::
  {:ok, OpenAi.Run.ListResponse.t()} | {:error, OpenAi.Error.error()}

Returns a list of runs belonging to a thread.

Options

  • limit: A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.

  • order: Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

  • after: A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.

  • before: A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.

Link to this function

modify_assistant(assistant_id, body, opts \\ [])

View Source
@spec modify_assistant(
  assistant_id :: String.t(),
  body :: OpenAi.Assistant.UpdateRequest.t(),
  opts :: keyword()
) :: {:ok, OpenAi.Assistant.t()} | {:error, OpenAi.Error.error()}

Modifies an assistant.

Link to this function

modify_message(thread_id, message_id, body, opts \\ [])

View Source
@spec modify_message(
  thread_id :: String.t(),
  message_id :: String.t(),
  body :: OpenAi.Message.UpdateRequest.t(),
  opts :: keyword()
) :: {:ok, OpenAi.Message.t()} | {:error, OpenAi.Error.error()}

Modifies a message.

Link to this function

modify_run(thread_id, run_id, body, opts \\ [])

View Source
@spec modify_run(
  thread_id :: String.t(),
  run_id :: String.t(),
  body :: OpenAi.Run.UpdateRequest.t(),
  opts :: keyword()
) :: {:ok, OpenAi.Run.t()} | {:error, OpenAi.Error.error()}

Modifies a run.

Link to this function

modify_thread(thread_id, body, opts \\ [])

View Source
@spec modify_thread(
  thread_id :: String.t(),
  body :: OpenAi.Thread.UpdateRequest.t(),
  opts :: keyword()
) :: {:ok, OpenAi.Thread.t()} | {:error, OpenAi.Error.error()}

Modifies a thread.

Link to this function

submit_tool_outputs_to_run(thread_id, run_id, body, opts \\ [])

View Source
@spec submit_tool_outputs_to_run(
  thread_id :: String.t(),
  run_id :: String.t(),
  body :: OpenAi.Assistant.Tool.Outputs.RunSubmitRequest.t(),
  opts :: keyword()
) :: {:ok, OpenAi.Run.t()} | {:error, OpenAi.Error.error()}

When a run has the status: "requires_action" and required_action.type is submit_tool_outputs, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request.