Class: OpenAI::Resources::Beta::Assistants

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/resources/beta/assistants.rb,
sig/openai/resources/beta/assistants.rbs

Overview

Build Assistants that can call models and use tools.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Assistants

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Assistants.

Parameters:



309
310
311
# File 'lib/openai/resources/beta/assistants.rb', line 309

def initialize(client:)
  @client = client
end

Instance Method Details

#create(model:, description: nil, instructions: nil, metadata: nil, name: nil, reasoning_effort: nil, response_format: nil, temperature: nil, tool_resources: nil, tools: nil, top_p: nil, request_options: {}) ⇒ OpenAI::Models::Beta::Assistant

Deprecated.

Create an assistant with a model and instructions.

Parameters:

  • model (String, Symbol, OpenAI::Models::ChatModel)

    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.

  • description (String, nil)

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

  • instructions (String, nil)

    The system instructions that the assistant uses. The maximum length is 256,000 characters.

  • metadata (Hash{Symbol=>String}, nil)

    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, and querying for objects via API or the dashboard.

    Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

  • name (String, nil)

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

  • reasoning_effort (Symbol, OpenAI::Models::ReasoningEffort, nil)

    Constrains effort on reasoning for reasoning models. Currently supported values are none, minimal, low, medium, high, xhigh, and max. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response. Not all reasoning models support every value. See the reasoning guide for model-specific support.

  • response_format (Symbol, :auto, OpenAI::Models::ResponseFormatText, OpenAI::Models::ResponseFormatJSONObject, OpenAI::Models::ResponseFormatJSONSchema, nil)

    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 { "type": "json_schema", "json_schema": {...} } enables Structured Outputs which ensures the model will match your supplied JSON schema. Learn more in the Structured Outputs guide.

    Setting to { "type": "json_object" } enables JSON mode, which ensures 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.

  • temperature (Float, nil)

    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.

  • tool_resources (OpenAI::Models::Beta::AssistantCreateParams::ToolResources, nil)

    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.

  • tools (Array<OpenAI::Models::Beta::CodeInterpreterTool, OpenAI::Models::Beta::FileSearchTool, OpenAI::Models::Beta::FunctionTool>)

    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, file_search, or function.

  • top_p (Float, nil)

    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.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/openai/resources/beta/assistants.rb', line 97

def create(params)
  parsed, options = OpenAI::Beta::AssistantCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "assistants",
    body: parsed,
    model: OpenAI::Beta::Assistant,
    security: {bearer_auth: true},
    options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **options}
  )
end

#delete(assistant_id, request_options: {}) ⇒ OpenAI::Models::Beta::AssistantDeleted

Deprecated.

Delete an assistant.

Parameters:

  • assistant_id (String)

    The ID of the assistant to delete.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



296
297
298
299
300
301
302
303
304
# File 'lib/openai/resources/beta/assistants.rb', line 296

def delete(assistant_id, params = {})
  @client.request(
    method: :delete,
    path: ["assistants/%1$s", assistant_id],
    model: OpenAI::Beta::AssistantDeleted,
    security: {bearer_auth: true},
    options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **params[:request_options].to_h}
  )
end

#list(after: nil, before: nil, limit: nil, order: nil, request_options: {}) ⇒ OpenAI::Internal::CursorPage<OpenAI::Models::Beta::Assistant>

Deprecated.

Returns a list of assistants.

Parameters:

  • after (String)

    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 (String)

    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.

  • limit (Integer)

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

  • order (Symbol, OpenAI::Models::Beta::AssistantListParams::Order)

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

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/openai/resources/beta/assistants.rb', line 268

def list(params = {})
  parsed, options = OpenAI::Beta::AssistantListParams.dump_request(params)
  query = OpenAI::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "assistants",
    query: query,
    page: OpenAI::Internal::CursorPage,
    model: OpenAI::Beta::Assistant,
    security: {bearer_auth: true},
    options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **options}
  )
end

#retrieve(assistant_id, request_options: {}) ⇒ OpenAI::Models::Beta::Assistant

Deprecated.

Retrieves an assistant.

Parameters:

  • assistant_id (String)

    The ID of the assistant to retrieve.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



123
124
125
126
127
128
129
130
131
# File 'lib/openai/resources/beta/assistants.rb', line 123

def retrieve(assistant_id, params = {})
  @client.request(
    method: :get,
    path: ["assistants/%1$s", assistant_id],
    model: OpenAI::Beta::Assistant,
    security: {bearer_auth: true},
    options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **params[:request_options].to_h}
  )
end

#update(assistant_id, description: nil, instructions: nil, metadata: nil, model: nil, name: nil, reasoning_effort: nil, response_format: nil, temperature: nil, tool_resources: nil, tools: nil, top_p: nil, request_options: {}) ⇒ OpenAI::Models::Beta::Assistant

Deprecated.

Modifies an assistant.

Parameters:

  • assistant_id (String)

    The ID of the assistant to modify.

  • description (String, nil)

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

  • instructions (String, nil)

    The system instructions that the assistant uses. The maximum length is 256,000 characters.

  • metadata (Hash{Symbol=>String}, nil)

    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, and querying for objects via API or the dashboard.

    Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

  • model (String, Symbol, OpenAI::Models::Beta::AssistantUpdateParams::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 (String, nil)

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

  • reasoning_effort (Symbol, OpenAI::Models::ReasoningEffort, nil)

    Constrains effort on reasoning for reasoning models. Currently supported values are none, minimal, low, medium, high, xhigh, and max. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response. Not all reasoning models support every value. See the reasoning guide for model-specific support.

  • response_format (Symbol, :auto, OpenAI::Models::ResponseFormatText, OpenAI::Models::ResponseFormatJSONObject, OpenAI::Models::ResponseFormatJSONSchema, nil)

    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 { "type": "json_schema", "json_schema": {...} } enables Structured Outputs which ensures the model will match your supplied JSON schema. Learn more in the Structured Outputs guide.

    Setting to { "type": "json_object" } enables JSON mode, which ensures 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.

  • temperature (Float, nil)

    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.

  • tool_resources (OpenAI::Models::Beta::AssistantUpdateParams::ToolResources, nil)

    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.

  • tools (Array<OpenAI::Models::Beta::CodeInterpreterTool, OpenAI::Models::Beta::FileSearchTool, OpenAI::Models::Beta::FunctionTool>)

    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, file_search, or function.

  • top_p (Float, nil)

    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.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



225
226
227
228
229
230
231
232
233
234
235
# File 'lib/openai/resources/beta/assistants.rb', line 225

def update(assistant_id, params = {})
  parsed, options = OpenAI::Beta::AssistantUpdateParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["assistants/%1$s", assistant_id],
    body: parsed,
    model: OpenAI::Beta::Assistant,
    security: {bearer_auth: true},
    options: {extra_headers: {"OpenAI-Beta" => "assistants=v2"}, **options}
  )
end