Skip to content

Commit 37c5fd5

Browse files
committed
Providers are disabled unless specifically configured
This is so that doing `models.refresh!` won't attempt to use every provider API, resulting in errors unless a valid key is given for every one. If this is too disruptive to be default behavior, then this could be a "default to offline" mode that needs to be explicitly turned on perhaps with an environment variable; in its absence, behavior would be the same as before. This is all so that `models.refresh!` can be called freely to populate Ollama models at runtime.
1 parent 0478a09 commit 37c5fd5

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

lib/ruby_llm/provider.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def complete(messages, tools:, temperature:, model:, &block) # rubocop:disable M
2929
end
3030

3131
def list_models
32+
return [] unless enabled?
33+
3234
response = connection.get(models_url) do |req|
3335
req.headers.merge! headers
3436
end

lib/ruby_llm/providers/anthropic.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ module Anthropic
1515

1616
module_function
1717

18+
def enabled?
19+
!! RubyLLM.config.anthropic_api_key
20+
end
21+
1822
def api_base
1923
'https://api.anthropic.com'
2024
end

lib/ruby_llm/providers/deepseek.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ module DeepSeek
88

99
module_function
1010

11+
def enabled?
12+
!! RubyLLM.config.deepseek_api_key
13+
end
14+
1115
def api_base
1216
'https://api.deepseek.com'
1317
end

lib/ruby_llm/providers/gemini.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ module Gemini
1515

1616
module_function
1717

18+
def enabled?
19+
!! RubyLLM.config.gemini_api_key
20+
end
21+
1822
def api_base
1923
'https://generativelanguage.googleapis.com/v1beta'
2024
end

lib/ruby_llm/providers/openai.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def self.extended(base)
2828

2929
module_function
3030

31+
def enabled?
32+
!! RubyLLM.config.openai_api_key
33+
end
34+
3135
def api_base
3236
'https://api.openai.com/v1'
3337
end

0 commit comments

Comments
 (0)