Module: RubyLLM::Providers::XAI::ChatCompletions::Batches
- Includes:
- Batch::Helpers
- Defined in:
- lib/ruby_llm/providers/xai/chat_completions/batches.rb
Overview
xAI native batch containers. Requests submit in Responses or Chat Completions shape; results always come back as chat completions.
Instance Method Summary collapse
- #batch_results(id) ⇒ Object
- #cancel_batch(id) ⇒ Object
- #create_batch(requests) ⇒ Object
- #find_batch(id) ⇒ Object
Instance Method Details
#batch_results(id) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ruby_llm/providers/xai/chat_completions/batches.rb', line 31 def batch_results(id) results = [] token = nil loop do response = @connection.get("batches/#{id}/results") do |request| request.params[:limit] = 100 request.params[:pagination_token] = token if token end.body page_results = Array(response['results'] || response['batch_results']) results.concat(page_results.map { |result| parse_batch_result(result) }) token = response['pagination_token'] || response['next_page_token'] break unless token end results end |
#cancel_batch(id) ⇒ Object
27 28 29 |
# File 'lib/ruby_llm/providers/xai/chat_completions/batches.rb', line 27 def cancel_batch(id) parse_batch_response @connection.post("batches/#{id}:cancel", {}).body end |
#create_batch(requests) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ruby_llm/providers/xai/chat_completions/batches.rb', line 12 def create_batch(requests) batch = @connection.post('batches', { name: "ruby_llm_#{SecureRandom.hex(8)}" }, idempotent: false).body id = batch['batch_id'] || batch['id'] @connection.post("batches/#{id}/requests", { batch_requests: requests.map { |request| xai_batch_request(request) } }, idempotent: false) find_batch(id) end |
#find_batch(id) ⇒ Object
23 24 25 |
# File 'lib/ruby_llm/providers/xai/chat_completions/batches.rb', line 23 def find_batch(id) parse_batch_response @connection.get("batches/#{id}").body end |