Module: RubyLLM::Providers::Mistral::ChatCompletions::Batches
- Includes:
- Batch::Helpers
- Defined in:
- lib/ruby_llm/providers/mistral/chat_completions/batches.rb
Overview
Mistral batch jobs for chat completions and embeddings.
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
43 44 45 46 |
# File 'lib/ruby_llm/providers/mistral/chat_completions/batches.rb', line 43 def batch_results(id) response = @connection.get(batch_url(id)) { |request| request.params[:inline] = true } Array(response.body['outputs']).filter_map { |line| parse_batch_result(line) } end |
#cancel_batch(id) ⇒ Object
39 40 41 |
# File 'lib/ruby_llm/providers/mistral/chat_completions/batches.rb', line 39 def cancel_batch(id) parse_batch_response @connection.post("#{batch_url(id)}/cancel", {}).body end |
#create_batch(requests) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ruby_llm/providers/mistral/chat_completions/batches.rb', line 15 def create_batch(requests) model = single_batch_model!(requests, 'mistral') response = @connection.post('batch/jobs', { endpoint: mistral_batch_endpoint(requests), model: model, requests: requests.map { |request| mistral_batch_request(request) } }, idempotent: false) parse_batch_response(response.body) end |
#find_batch(id) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby_llm/providers/mistral/chat_completions/batches.rb', line 26 def find_batch(id) attempts = 0 begin parse_batch_response @connection.get(batch_url(id)).body rescue Error => e attempts += 1 raise unless e.response&.status == 404 && attempts < 3 sleep(0.5 * attempts) retry end end |