Skip to contents

Build assistants that can call models and use tools to perform tasks.

  • oai_create_assistant(): Create an assistant with a model and instructions.

  • oai_modify_assistant(): Modify an assistant's properties.

  • oai_list_assistants(): List all assistants.

  • oai_retrieve_assistant(): Retrieve an assistant.

  • oai_delete_assistant(): Delete an assistant.

Usage

oai_create_assistant(
  model,
  name = NULL,
  description = NULL,
  instructions = NULL,
  tools = NULL,
  tool_resources = NULL,
  metadata = NULL,
  temperature = NULL,
  top_p = NULL,
  response_format = NULL,
  .classify_response = TRUE,
  .async = FALSE
)

oai_modify_assistant(
  assistant_id,
  model = NULL,
  name = NULL,
  description = NULL,
  instructions = NULL,
  tools = NULL,
  tool_resources = NULL,
  metadata = NULL,
  temperature = NULL,
  top_p = NULL,
  response_format = NULL,
  .classify_response = TRUE,
  .async = FALSE
)

oai_list_assistants(
  limit = NULL,
  order = NULL,
  after = NULL,
  before = NULL,
  .classify_response = TRUE
)

oai_retrieve_assistant(assistant_id, .classify_response = TRUE, .async = FALSE)

oai_delete_assistant(assistant_id, .async = FALSE)

Arguments

model

Character. ID of the model to use. You can use the oai_list_models() to see all of your available models.

name

Character or NULL. Optional. The name of the assistant. The maximum length is 256 characters.

description

Character or NULL. Optional. The description of the assistant. The maximum length is 512 characters.

instructions

Character or NULL. Optional. The system instructions that the assistant uses. The maximum length is 256,000 characters.

tools

List. Optional. Defaults to NULL. A list of tools enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types code_interpreter, file_search, or function.

tool_resources

List. Optional. A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the code_interpreter tool requires a list of file IDs, while the file_search tool requires a list of vector store IDs.

metadata

List. Optional. 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 maximum of 512 characters long.

temperature

Numeric. Optional. Defaults to 1. What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.

top_p

Numeric. Optional. Defaults to 1. An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.

response_format

Character or List. Optional. Specifies the format that the model must output. Compatible with GPT-4o, GPT-4 Turbo, and all GPT-3.5 Turbo models since gpt-3.5-turbo-1106. Setting to list(type = "json_object") enables JSON mode, which guarantees the message the model generates is valid JSON. Important: when using JSON mode, you must also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if finish_reason="length", which indicates the generation exceeded max_tokens or the conversation exceeded the max context length.

.classify_response

Logical. If TRUE (default), the response is classified as an R6 object. If FALSE, the response is returned as a list.

.async

Logical. If TRUE, the request is performed asynchronously.

assistant_id

Character. The ID of the assistant to retrieve.

limit

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

order

Character. Optional. Sort order by the created_at timestamp of the objects. "asc" for ascending order and "desc" for descending order.

after

Character. Optional. 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

Character. Optional. 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, ending with obj_foo, your subsequent call can include before = "obj_foo" in order to fetch the previous page of the list.

Value

Functions oai_create_assistant(), oai_modify_assistant(), and oai_retrieve_assistant() return an Assistant R6 object.

Function oai_list_assistants() returns a list of Assistant R6 objects.

Function oai_delete_assistant() returns the deletion status.