Skip to content

Commit e2edea7

Browse files
committed
feat: add configurable retry settings for API requests
1 parent d68c226 commit e2edea7

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

lib/ruby_llm/configuration.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module RubyLLM
1010
# config.anthropic_api_key = ENV['ANTHROPIC_API_KEY']
1111
# end
1212
class Configuration
13+
# Provider-specific configuration
1314
attr_accessor :openai_api_key,
1415
:anthropic_api_key,
1516
:gemini_api_key,
@@ -18,15 +19,26 @@ class Configuration
1819
:bedrock_secret_key,
1920
:bedrock_region,
2021
:bedrock_session_token,
22+
# Default models
2123
:default_model,
2224
:default_embedding_model,
2325
:default_image_model,
26+
# Connection configuration
2427
:request_timeout,
25-
:max_retries
28+
:max_retries,
29+
:retry_interval,
30+
:retry_backoff_factor,
31+
:retry_interval_randomness
2632

2733
def initialize
34+
# Connection configuration
2835
@request_timeout = 120
2936
@max_retries = 3
37+
@retry_interval = 0.1
38+
@retry_backoff_factor = 2
39+
@retry_interval_randomness = 0.5
40+
41+
# Default models
3042
@default_model = 'gpt-4o-mini'
3143
@default_embedding_model = 'text-embedding-3-small'
3244
@default_image_model = 'dall-e-3'

lib/ruby_llm/provider.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ def connection # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
108108

109109
f.request :retry, {
110110
max: RubyLLM.config.max_retries,
111-
interval: 0.1,
112-
interval_randomness: 0.5,
113-
backoff_factor: 2,
111+
interval: RubyLLM.config.retry_interval,
112+
interval_randomness: RubyLLM.config.retry_interval_randomness,
113+
backoff_factor: RubyLLM.config.retry_backoff_factor,
114114
exceptions: [
115115
Errno::ETIMEDOUT,
116116
Timeout::Error,

spec/spec_helper.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@
9999
config.bedrock_region = 'us-west-2'
100100
config.bedrock_session_token = ENV.fetch('AWS_SESSION_TOKEN', nil)
101101

102-
config.max_retries = 50
102+
config.max_retries = 10
103+
config.retry_interval = 1
104+
config.retry_backoff_factor = 3
105+
config.retry_interval_randomness = 0.5
103106
end
104107
end
105108
end

0 commit comments

Comments
 (0)