Module: RubyLLM::Protocols::Anthropic::Batches
- Includes:
- Batch::Helpers
- Defined in:
- lib/ruby_llm/protocols/anthropic/batches.rb
Overview
The Message Batches API: Messages requests processed together, asynchronously, at half price.
Instance Method Summary collapse
-
#batch_results(id) ⇒ Object
Results come back as JSONL in no particular order; each line carries the custom_id (our submission index) to match results to requests.
- #cancel_batch(id) ⇒ Object
- #create_batch(requests) ⇒ Object
- #find_batch(id) ⇒ Object
Instance Method Details
#batch_results(id) ⇒ Object
Results come back as JSONL in no particular order; each line carries the custom_id (our submission index) to match results to requests.
27 28 29 30 |
# File 'lib/ruby_llm/protocols/anthropic/batches.rb', line 27 def batch_results(id) response = @connection.get "#{batch_url(id)}/results" response.body.each_line.map { |line| parse_batch_result JSON.parse(line) } end |
#cancel_batch(id) ⇒ Object
21 22 23 |
# File 'lib/ruby_llm/protocols/anthropic/batches.rb', line 21 def cancel_batch(id) parse_batch_response @connection.post("#{batch_url(id)}/cancel", {}).body end |
#create_batch(requests) ⇒ Object
11 12 13 14 15 |
# File 'lib/ruby_llm/protocols/anthropic/batches.rb', line 11 def create_batch(requests) requests = requests.map { |request| { custom_id: request[:custom_id], params: request[:payload] } } response = @connection.post batches_url, { requests: requests }, idempotent: false parse_batch_response response.body end |
#find_batch(id) ⇒ Object
17 18 19 |
# File 'lib/ruby_llm/protocols/anthropic/batches.rb', line 17 def find_batch(id) parse_batch_response @connection.get(batch_url(id)).body end |