Skip to content

Add support for customizing the model file path #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ruby_llm/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_llm/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
16 changes: 16 additions & 0 deletions spec/ruby_llm/models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down