Class: OpenAI::Resources::Batches

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/resources/batches.rb

Overview

Create large batches of API requests to run asynchronously.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Batches

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

Parameters:



108
109
110
# File 'lib/openai/resources/batches.rb', line 108

def initialize(client:)
  @client = client
end

Instance Method Details

#cancel(batch_id, request_options: {}) ⇒ OpenAI::Models::Batch

Cancels an in-progress batch. The batch will be in status ‘cancelling` for up to 10 minutes, before changing to `cancelled`, where it will have partial results (if any) available in the output file.

Parameters:

  • batch_id (String)

    The ID of the batch to cancel.

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

Returns:

See Also:



96
97
98
99
100
101
102
103
# File 'lib/openai/resources/batches.rb', line 96

def cancel(batch_id, params = {})
  @client.request(
    method: :post,
    path: ["batches/%1$s/cancel", batch_id],
    model: OpenAI::Batch,
    options: params[:request_options]
  )
end

#create(completion_window:, endpoint:, input_file_id:, metadata: nil, output_expires_after: nil, request_options: {}) ⇒ OpenAI::Models::Batch

Some parameter documentations has been truncated, see Models::BatchCreateParams for more details.

Creates and executes a batch from an uploaded file of requests

Parameters:

Returns:

See Also:



29
30
31
32
# File 'lib/openai/resources/batches.rb', line 29

def create(params)
  parsed, options = OpenAI::BatchCreateParams.dump_request(params)
  @client.request(method: :post, path: "batches", body: parsed, model: OpenAI::Batch, options: options)
end

#list(after: nil, limit: nil, request_options: {}) ⇒ OpenAI::Internal::CursorPage<OpenAI::Models::Batch>

Some parameter documentations has been truncated, see Models::BatchListParams for more details.

List your organization’s batches.

Parameters:

  • after (String)

    A cursor for use in pagination. ‘after` is an object ID that defines your place

  • limit (Integer)

    A limit on the number of objects to be returned. Limit can range between 1 and 1

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

Returns:

See Also:



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/openai/resources/batches.rb', line 70

def list(params = {})
  parsed, options = OpenAI::BatchListParams.dump_request(params)
  query = OpenAI::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "batches",
    query: query,
    page: OpenAI::Internal::CursorPage,
    model: OpenAI::Batch,
    options: options
  )
end

#retrieve(batch_id, request_options: {}) ⇒ OpenAI::Models::Batch

Retrieves a batch.

Parameters:

  • batch_id (String)

    The ID of the batch to retrieve.

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

Returns:

See Also:



45
46
47
48
49
50
51
52
# File 'lib/openai/resources/batches.rb', line 45

def retrieve(batch_id, params = {})
  @client.request(
    method: :get,
    path: ["batches/%1$s", batch_id],
    model: OpenAI::Batch,
    options: params[:request_options]
  )
end