Class: Anthropic::Messages::Batches
- Inherits:
-
Object
- Object
- Anthropic::Messages::Batches
- Defined in:
- lib/anthropic/messages/batches.rb
Constant Summary collapse
- BETA_VERSION =
"message-batches-2024-09-24".freeze
Instance Method Summary collapse
-
#cancel(id:) ⇒ Object
Anthropic API Parameters as of 2024-10-09: Cancel a Message Batch.
-
#create(parameters: {}) ⇒ Object
Anthropic API Parameters as of 2024-10-09: Each is an individual request to create a Message.
-
#get(id:) ⇒ Object
Anthropic API Parameters as of 2024-10-09:.
-
#initialize(client) ⇒ Batches
constructor
A new instance of Batches.
-
#list(parameters: {}) ⇒ Object
Anthropic API Parameters as of 2024-10-09: List all Message Batches within a Workspace.
-
#results(id:) ⇒ Object
Anthropic API Parameters as of 2024-10-09: Returns the results of a Message Batch as a .jsonl file.
Constructor Details
#initialize(client) ⇒ Batches
Returns a new instance of Batches.
6 7 8 |
# File 'lib/anthropic/messages/batches.rb', line 6 def initialize(client) @client = client.beta(BETA_VERSION) end |
Instance Method Details
#cancel(id:) ⇒ Object
Anthropic API Parameters as of 2024-10-09: Cancel a Message Batch. Batches may be canceled any time before processing ends. Once cancellation is initiated, the batch enters a canceling state, at which time the system may complete any in-progress, non-interruptible requests before finalizing cancellation.
The number of canceled requests is specified in request_counts. To determine which requests were canceled, check the individual results within the batch. Note that cancellation may not cancel any requests if they were non-interruptible.
107 108 109 |
# File 'lib/anthropic/messages/batches.rb', line 107 def cancel(id:) @client.json_post(path: "/messages/batches/#{id}/cancel") end |
#create(parameters: {}) ⇒ Object
Anthropic API Parameters as of 2024-10-09: Each is an individual request to create a Message. Parameters are an array of hashes, each with the following keys:
-
:custom_id (required): Developer-provided ID created for each request in a Message Batch.
Useful for matching results to requests, as results may be given out of request order. Must be unique for each request within the Message Batch.
-
:params (required): Messages API creation parameters for the individual request.
See the Messages API reference for full documentation on available parameters.
@example:
> messages.batches.create(parameters: [message1, message2]) {
"id"=>"msgbatch_01668jySCZeCpMLsxFcroNnN",
"type"=>"message_batch",
"processing_status"=>"in_progress",
"request_counts"=>{
"processing"=>2,
"succeeded"=>0,
"errored"=>0,
"canceled"=>0,
"expired"=>0
},
"ended_at"=>nil,
"created_at"=>"2024-10-09T20:18:11.480471+00:00",
"expires_at"=>"2024-10-10T20:18:11.480471+00:00",
"cancel_initiated_at"=>nil,
"results_url"=>nil
}
43 44 45 46 47 48 |
# File 'lib/anthropic/messages/batches.rb', line 43 def create(parameters: {}) @client.json_post( path: "/messages/batches", parameters: parameters ) end |
#get(id:) ⇒ Object
Anthropic API Parameters as of 2024-10-09:
56 57 58 |
# File 'lib/anthropic/messages/batches.rb', line 56 def get(id:) @client.get(path: "/messages/batches/#{id}") end |
#list(parameters: {}) ⇒ Object
Anthropic API Parameters as of 2024-10-09: List all Message Batches within a Workspace. Most recently created batches returned first. When provided, returns the page of results immediately before this object.
When provided, returns the page of results immediately after this object.
Defaults to 20. Ranges from 1 to 100.
88 89 90 |
# File 'lib/anthropic/messages/batches.rb', line 88 def list(parameters: {}) @client.get(path: "/messages/batches", parameters: parameters) end |
#results(id:) ⇒ Object
Anthropic API Parameters as of 2024-10-09: Returns the results of a Message Batch as a .jsonl file. Each line in the file is a JSON object containing the result of a single request in the Message Batch. Results are not guaranteed to be in the same order as requests. Use the custom_id field to match results to requests.
70 71 72 |
# File 'lib/anthropic/messages/batches.rb', line 70 def results(id:) @client.get(path: "/messages/batches/#{id}/results") end |