Skip to content

Commit 04d4409

Browse files
committed
Filter remote providers when fetching models and simplify specs for refresh method
1 parent 44d59ab commit 04d4409

File tree

2 files changed

+16
-34
lines changed

2 files changed

+16
-34
lines changed

lib/ruby_llm/models.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def refresh!
3737
end
3838

3939
def fetch_from_providers
40-
configured = Provider.configured_providers(RubyLLM.config)
40+
configured = Provider.configured_providers(RubyLLM.config).filter(&:remote?)
4141

4242
RubyLLM.logger.info "Fetching models from providers: #{configured.map(&:slug).join(', ')}"
4343

spec/ruby_llm/models_spec.rb

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -78,42 +78,24 @@
7878
end
7979

8080
describe '#refresh!' do
81-
it 'updates models and returns a chainable Models instance' do # rubocop:disable RSpec/ExampleLength,RSpec/MultipleExpectations
82-
# Use a temporary file to avoid modifying actual models.json
83-
temp_file = Tempfile.new(['models', '.json'])
84-
allow(File).to receive(:expand_path).with('models.json', any_args).and_return(temp_file.path)
85-
86-
begin
87-
# Refresh and chain immediately
88-
chat_models = RubyLLM.models.refresh!.chat_models
89-
90-
# Verify we got results
91-
expect(chat_models).to be_a(described_class)
92-
expect(chat_models.all).to all(have_attributes(type: 'chat'))
93-
94-
# Verify we got models from at least OpenAI and Anthropic
95-
providers = chat_models.map(&:provider).uniq
96-
expect(providers).to include('openai', 'anthropic')
97-
ensure
98-
temp_file.close
99-
temp_file.unlink
100-
end
101-
end
81+
it 'updates models and returns a chainable Models instance' do # rubocop:disable RSpec/MultipleExpectations
82+
# Refresh and chain immediately
83+
chat_models = RubyLLM.models.refresh!.chat_models
10284

103-
it 'works as a class method too' do # rubocop:disable RSpec/ExampleLength
104-
temp_file = Tempfile.new(['models', '.json'])
105-
allow(File).to receive(:expand_path).with('models.json', any_args).and_return(temp_file.path)
85+
# Verify we got results
86+
expect(chat_models).to be_a(described_class)
87+
expect(chat_models.all).to all(have_attributes(type: 'chat'))
10688

107-
begin
108-
# Call class method
109-
described_class.refresh!
89+
# Verify we got models from at least OpenAI and Anthropic
90+
providers = chat_models.map(&:provider).uniq
91+
expect(providers).to include('openai', 'anthropic')
92+
end
11093

111-
# Verify singleton instance was updated
112-
expect(RubyLLM.models.all.size).to be > 0
113-
ensure
114-
temp_file.close
115-
temp_file.unlink
116-
end
94+
it 'works as a class method too' do
95+
described_class.refresh!
96+
97+
# Verify singleton instance was updated
98+
expect(RubyLLM.models.all.size).to be > 0
11799
end
118100
end
119101

0 commit comments

Comments
 (0)