Class: Whitebox::Client
- Inherits:
-
Object
- Object
- Whitebox::Client
- Defined in:
- lib/whitebox/client.rb
Constant Summary collapse
- BASE_URL =
"https://whiteboxhq.ai/api/v1"
Instance Method Summary collapse
-
#decide(input:, options:, prompt: nil, runs: 7, threshold: 0.75, sync: true, mode: "standard", models: nil) ⇒ Object
Single decision.
-
#decide_bulk(items:, prompt: nil, options: nil, runs: 7, threshold: 0.75, webhook_url: nil) ⇒ Object
Bulk decisions.
-
#decide_fast(input:, options:, prompt: nil, threshold: 0.75) ⇒ Object
Fast mode: 3 runs, 2 models, sync.
-
#get_batch(id) ⇒ Object
Get batch status.
-
#get_batch_results(id) ⇒ Object
Get batch results.
-
#get_decision(id) ⇒ Object
Get a single decision.
-
#initialize(api_key:, base_url: nil, timeout: 30) ⇒ Client
constructor
A new instance of Client.
-
#list_decisions(page: 1, per_page: 20) ⇒ Object
List decisions.
-
#list_reviews ⇒ Object
List pending reviews.
-
#models ⇒ Object
List supported models.
-
#resolve_review(id, answer:) ⇒ Object
Resolve a review.
Constructor Details
Instance Method Details
#decide(input:, options:, prompt: nil, runs: 7, threshold: 0.75, sync: true, mode: "standard", models: nil) ⇒ Object
Single decision
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/whitebox/client.rb', line 16 def decide(input:, options:, prompt: nil, runs: 7, threshold: 0.75, sync: true, mode: "standard", models: nil) body = { input: input, options: , prompt: prompt, runs: runs, threshold: threshold, sync: sync, mode: mode, } body[:models] = models if models data = request(:post, "/decide", body) Decision.from_hash(data) end |
#decide_bulk(items:, prompt: nil, options: nil, runs: 7, threshold: 0.75, webhook_url: nil) ⇒ Object
Bulk decisions
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/whitebox/client.rb', line 38 def decide_bulk(items:, prompt: nil, options: nil, runs: 7, threshold: 0.75, webhook_url: nil) body = { items: items, prompt: prompt, options: , runs: runs, threshold: threshold, webhook_url: webhook_url, }.compact data = request(:post, "/decide/bulk", body) Batch.from_hash(data) end |
#decide_fast(input:, options:, prompt: nil, threshold: 0.75) ⇒ Object
Fast mode: 3 runs, 2 models, sync
33 34 35 |
# File 'lib/whitebox/client.rb', line 33 def decide_fast(input:, options:, prompt: nil, threshold: 0.75) decide(input: input, options: , prompt: prompt, threshold: threshold, mode: "fast", sync: true) end |
#get_batch(id) ⇒ Object
Get batch status
65 66 67 68 |
# File 'lib/whitebox/client.rb', line 65 def get_batch(id) data = request(:get, "/batches/#{id}") Batch.from_hash(data) end |
#get_batch_results(id) ⇒ Object
Get batch results
71 72 73 |
# File 'lib/whitebox/client.rb', line 71 def get_batch_results(id) request(:get, "/batches/#{id}/results") end |
#get_decision(id) ⇒ Object
Get a single decision
53 54 55 56 |
# File 'lib/whitebox/client.rb', line 53 def get_decision(id) data = request(:get, "/decisions/#{id}") Decision.from_hash(data) end |
#list_decisions(page: 1, per_page: 20) ⇒ Object
List decisions
59 60 61 62 |
# File 'lib/whitebox/client.rb', line 59 def list_decisions(page: 1, per_page: 20) data = request(:get, "/decisions?page=#{page}&per_page=#{per_page}") (data["decisions"] || []).map { |d| Decision.from_hash(d) } end |
#list_reviews ⇒ Object
List pending reviews
76 77 78 79 |
# File 'lib/whitebox/client.rb', line 76 def list_reviews data = request(:get, "/reviews") (data.is_a?(Array) ? data : []).map { |r| Review.from_hash(r) } end |
#models ⇒ Object
List supported models
88 89 90 |
# File 'lib/whitebox/client.rb', line 88 def models request(:get, "/models") end |