@@ -10,7 +10,7 @@ module Provider
10
10
module Methods
11
11
extend Streaming
12
12
13
- def complete ( messages , tools :, temperature :, model :, &block ) # rubocop:disable Metrics/MethodLength
13
+ def complete ( messages , tools :, temperature :, model :, config : , &block ) # rubocop:disable Metrics/MethodLength
14
14
normalized_temperature = if capabilities . respond_to? ( :normalize_temperature )
15
15
capabilities . normalize_temperature ( temperature , model )
16
16
else
@@ -24,9 +24,9 @@ def complete(messages, tools:, temperature:, model:, &block) # rubocop:disable M
24
24
stream : block_given? )
25
25
26
26
if block_given?
27
- stream_response payload , &block
27
+ stream_response ( payload , config , &block )
28
28
else
29
- sync_response payload
29
+ sync_response ( payload , config )
30
30
end
31
31
end
32
32
@@ -51,49 +51,50 @@ def paint(prompt, model:, size:)
51
51
parse_image_response ( response )
52
52
end
53
53
54
- def configured?
55
- missing_configs . empty?
54
+ def configured? ( config = nil )
55
+ config ||= RubyLLM . config
56
+ missing_configs ( config ) . empty?
56
57
end
57
58
58
59
private
59
60
60
- def missing_configs
61
+ def missing_configs ( config )
61
62
configuration_requirements . select do |key |
62
- value = RubyLLM . config . send ( key )
63
+ value = config . send ( key )
63
64
value . nil? || value . empty?
64
65
end
65
66
end
66
67
67
- def ensure_configured!
68
- return if configured?
68
+ def ensure_configured! ( config )
69
+ return if configured? ( config )
69
70
70
71
config_block = <<~RUBY
71
- RubyLLM.configure do |config |
72
- #{ missing_configs . map { |key | "config .#{ key } = ENV['#{ key . to_s . upcase } ']" } . join ( "\n " ) }
72
+ RubyLLM.configure do |c |
73
+ #{ missing_configs ( config ) . map { |key | "c .#{ key } = ENV['#{ key . to_s . upcase } ']" } . join ( "\n " ) }
73
74
end
74
75
RUBY
75
76
76
77
raise ConfigurationError ,
77
78
"#{ slug } provider is not configured. Add this to your initialization:\n \n #{ config_block } "
78
79
end
79
80
80
- def sync_response ( payload )
81
- response = post completion_url , payload
82
- parse_completion_response response
81
+ def sync_response ( payload , config )
82
+ response = post ( completion_url , payload , config )
83
+ parse_completion_response ( response )
83
84
end
84
85
85
- def post ( url , payload )
86
- connection . post url , payload do |req |
87
- req . headers . merge! headers
86
+ def post ( url , payload , config )
87
+ connection ( config ) . post ( url , payload ) do |req |
88
+ req . headers . merge! headers ( config )
88
89
yield req if block_given?
89
90
end
90
91
end
91
92
92
- def connection # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
93
- ensure_configured!
93
+ def connection ( config ) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
94
+ ensure_configured! ( config )
94
95
95
96
@connection ||= Faraday . new ( api_base ) do |f | # rubocop:disable Metrics/BlockLength
96
- f . options . timeout = RubyLLM . config . request_timeout
97
+ f . options . timeout = config . request_timeout
97
98
98
99
f . response :logger ,
99
100
RubyLLM . logger ,
@@ -107,7 +108,7 @@ def connection # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
107
108
end
108
109
109
110
f . request :retry , {
110
- max : RubyLLM . config . max_retries ,
111
+ max : config . max_retries ,
111
112
interval : 0.05 ,
112
113
interval_randomness : 0.5 ,
113
114
backoff_factor : 2 ,
0 commit comments