class Anthropic::Client
def calculate_nonstreaming_timeout(max_tokens, max_nonstreaming_tokens = nil)
-
(ArgumentError)
- If expected time exceeds default time or max_tokens exceeds max_nonstreaming_tokens
Returns:
-
(Float)
- The calculated timeout in seconds
Parameters:
-
max_nonstreaming_tokens
(Integer, nil
) -- The maximum tokens allowed for non-streaming -
max_tokens
(Integer
) -- The maximum number of tokens to generate
def calculate_nonstreaming_timeout(max_tokens, max_nonstreaming_tokens = nil) maximum_time = 60 * 60 # 1 hour in seconds default_time = 60 * 10 # 10 minutes in seconds expected_time = maximum_time * max_tokens / 128_000.0 if expected_time > default_time || (max_nonstreaming_tokens && max_tokens > max_nonstreaming_tokens) raise ArgumentError.new( "Streaming is required for operations that may take longer than 10 minutes. " \ "See https://github.com/anthropics/anthropic-sdk-ruby#long-requests for more details" ) end DEFAULT_TIMEOUT_IN_SECONDS end