Skip to content

Commit 7da81ee

Browse files
Add resolve method delegation from Models instance to class
The migration template uses RubyLLM.models.resolve which requires the instance to delegate to the class method. This commit adds the missing delegation and comprehensive tests using TDD approach. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fa10f0c commit 7da81ee

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

lib/ruby_llm/models.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ def refresh!(remote_only: false)
217217
self.class.refresh!(remote_only: remote_only)
218218
end
219219

220+
def resolve(model_id, provider: nil, assume_exists: false, config: nil)
221+
self.class.resolve(model_id, provider: provider, assume_exists: assume_exists, config: config)
222+
end
223+
220224
private
221225

222226
def find_with_provider(model_id, provider)

spec/ruby_llm/models_spec.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,51 @@
143143
end
144144
end
145145

146+
describe '#resolve' do
147+
it 'delegates to the class method when called on instance' do
148+
# This tests that RubyLLM.models.resolve works
149+
# which is needed in the migration template
150+
model_id = 'gpt-4o'
151+
provider = 'openai'
152+
153+
# Call resolve on the instance (RubyLLM.models returns an instance)
154+
model_info, provider_instance = RubyLLM.models.resolve(model_id, provider: provider)
155+
156+
expect(model_info).to be_a(RubyLLM::Model::Info)
157+
expect(model_info.id).to eq(model_id)
158+
expect(model_info.provider).to eq(provider)
159+
expect(provider_instance).to be_a(RubyLLM::Provider)
160+
end
161+
162+
it 'resolves model without provider' do
163+
model_id = 'gpt-4o'
164+
165+
# Should resolve based on model ID alone
166+
model_info, provider_instance = RubyLLM.models.resolve(model_id)
167+
168+
expect(model_info).to be_a(RubyLLM::Model::Info)
169+
expect(model_info.id).to eq(model_id)
170+
expect(provider_instance).to be_a(RubyLLM::Provider)
171+
end
172+
173+
it 'resolves with assume_exists option' do
174+
model_id = 'custom-model'
175+
provider = 'openai'
176+
177+
# When assume_exists is true, it should create a default model
178+
model_info, provider_instance = RubyLLM.models.resolve(
179+
model_id,
180+
provider: provider,
181+
assume_exists: true
182+
)
183+
184+
expect(model_info).to be_a(RubyLLM::Model::Info)
185+
expect(model_info.id).to eq(model_id)
186+
expect(model_info.provider).to eq(provider)
187+
expect(provider_instance).to be_a(RubyLLM::Provider)
188+
end
189+
end
190+
146191
describe '#save_to_json' do
147192
it 'saves models to the models.json file' do
148193
temp_file = Tempfile.new(['models', '.json'])

0 commit comments

Comments
 (0)