From d7df2bd4e57710aead4622b6ff2fafb8652ee293 Mon Sep 17 00:00:00 2001 From: Daniel Westendorf Date: Fri, 15 Aug 2025 16:05:21 -0600 Subject: [PATCH] Add support for customizing the model file path --- lib/ruby_llm/configuration.rb | 4 ++++ lib/ruby_llm/models.rb | 2 +- spec/ruby_llm/models_spec.rb | 16 ++++++++++++++++ spec/spec_helper.rb | 2 ++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/ruby_llm/configuration.rb b/lib/ruby_llm/configuration.rb index 2f49746a..71676a86 100644 --- a/lib/ruby_llm/configuration.rb +++ b/lib/ruby_llm/configuration.rb @@ -29,6 +29,8 @@ class Configuration :gpustack_api_base, :gpustack_api_key, :mistral_api_key, + # Model configuration + :model_file_path, # Default models :default_model, :default_embedding_model, @@ -55,6 +57,8 @@ def initialize @retry_interval_randomness = 0.5 @http_proxy = nil + @model_file_path = File.expand_path('models.json', __dir__) + # Default models @default_model = 'gpt-4.1-nano' @default_embedding_model = 'text-embedding-3-small' diff --git a/lib/ruby_llm/models.rb b/lib/ruby_llm/models.rb index 99fa2aa9..24965910 100644 --- a/lib/ruby_llm/models.rb +++ b/lib/ruby_llm/models.rb @@ -22,7 +22,7 @@ def provider_for(model) end def models_file - File.expand_path('models.json', __dir__) + RubyLLM.config.model_file_path end def refresh! diff --git a/spec/ruby_llm/models_spec.rb b/spec/ruby_llm/models_spec.rb index 1ce5bc9e..5b6419d3 100644 --- a/spec/ruby_llm/models_spec.rb +++ b/spec/ruby_llm/models_spec.rb @@ -11,6 +11,22 @@ described_class.instance_variable_set(:@instance, nil) end + describe 'models file' do + it 'uses the bundled model file by default' do + expect(described_class.models_file).to eq( + File.expand_path(File.join(__dir__, '..', '..', 'lib', 'ruby_llm', 'models.json')) + ) + end + + it 'supports customization' do + RubyLLM.config.model_file_path = File.join(Dir.tmpdir, 'foobar.json') + + expect(described_class.models_file).to eq( + File.join(Dir.tmpdir, 'foobar.json') + ) + end + end + describe 'filtering and chaining' do it 'filters models by provider' do openai_models = RubyLLM.models.by_provider('openai') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3ce35494..3c134c5e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -144,6 +144,8 @@ config.retry_interval = 1 config.retry_backoff_factor = 3 config.retry_interval_randomness = 0.5 + + config.model_file_path = File.expand_path(File.join(__dir__, '..', 'lib', 'ruby_llm', 'models.json')) end end end