Class: SavvyOpenrouter::Resources::Responses
- Defined in:
- lib/savvy_openrouter/resources/responses.rb
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from SavvyOpenrouter::Resources::Base
Instance Method Details
#create(**params) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/savvy_openrouter/resources/responses.rb', line 9 def create(**params) policy = ResponsesRetryPolicy.new(config.responses_retries) body = config.merge_responses_body(params) lm = logical_model_from_body(body) conn.with_call_context(endpoint: "responses", logical_model: lm) do attempt = 0 last_response = nil begin loop do attempt += 1 begin last_response = conn.post("/responses", body: body) rescue SavvyOpenrouter::ApiError => e raise e if attempt >= policy.max_attempts || !policy.retry_http_error?(e) policy.wait_after_attempt(attempt) next end return last_response unless policy.retry_response?(last_response) return last_response if attempt >= policy.max_attempts policy.wait_after_attempt(attempt) end ensure conn.flush_deferred_responses_log! end end end |