ask-core 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5579b4c8482eca770eebc83285f046ad7797d1a032f8d55e355028c7986a9776
4
- data.tar.gz: 4d21bf4c9c13690ff1368b01a364ff7f961de2347660fdb33bc989ff0635c418
3
+ metadata.gz: e87a2c3690127974ace8b8143002728a1eb6bebbaae9d54b321c5f4342c20485
4
+ data.tar.gz: 605fb219de7a80fcf33a97b21a9a2149f688e7bdd25a066484f235e41e127420
5
5
  SHA512:
6
- metadata.gz: b309f9490cde3fc1c6b0712757256804af5b34f562d7114596e8cf4c69f4fb273558afd05e5545bab22fdcce13f9d0bb2214f1ef3794776a96fea8576900804c
7
- data.tar.gz: 19ceabf03606c291b4edea7ec222cc8152d61a13be16429428906325d2334b21ff4c97d328731a2264c9b6f5b26c9dc0d34481c30dbb0e2d69f71a4d6b048dc3
6
+ metadata.gz: 1b8852000559343d48f693bb80cda7b7bc4ed9ecf935fc3e2336c80798277a35e31e4dd37a8453ae9d69adbc88a3e80650f26b6eaf64fa7d757f0711301106c1
7
+ data.tar.gz: 8713f24a5530fbc86f347016e3eb811e4e2ddb14cf5d08368bf6f8d28ffa3aa5c32127a91c75923146ffc3e940295a6edff2bab4c2df7838f50bd207e7dc3232
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.2.3] — 2026-07-14
2
+
3
+ ### Changed
4
+ - `Ask::ModelCatalog.find(model_id)` now returns `Array<Ask::ModelInfo>` (all matches) — provider preference disambiguation is removed. Provider-scoped `find(model_id, provider)` still returns a single model or raises.
5
+ - Removed `Ask::ModelCatalog::PROVIDER_PREFERENCE`. No preference list anywhere — all providers and models are treated equally.
6
+
1
7
  ## [0.2.2] — 2026-07-14
2
8
 
3
9
  ### Added
data/lib/ask/models.rb CHANGED
@@ -256,12 +256,11 @@ module Ask
256
256
  end
257
257
  end
258
258
 
259
- # Catalog of available AI models. Provides model resolution by name/ID,
260
- # filtering by capability, and refresh from the models.dev API.
259
+ # Catalog of available AI models.
261
260
  #
262
- # Ask::ModelCatalog.find("gpt-4o")
263
- # Ask::ModelCatalog.chat_models
264
- # Ask::ModelCatalog.refresh!
261
+ # Ask::ModelCatalog.find("gpt-4o") # => ModelInfo or raises
262
+ # Ask::ModelCatalog.find("gpt-4o", provider: "openai") # => ModelInfo or raises
263
+ # Ask::ModelCatalog.where("gpt-4o") # => [ModelInfo, ...] (all matches)
265
264
  #
266
265
  class ModelCatalog
267
266
  include Enumerable
@@ -269,17 +268,8 @@ module Ask
269
268
  # @return [String] URL for the models.dev API
270
269
  MODELS_DEV_URL = "https://models.dev/api.json".freeze
271
270
 
272
- # Ordered provider preference for disambiguation.
273
- PROVIDER_PREFERENCE = %w[
274
- openai anthropic gemini vertexai bedrock
275
- opencode opencode_go
276
- openrouter deepseek mistral perplexity xai
277
- mimo
278
- azure ollama gpustack github
279
- ].freeze
280
-
281
271
  # Methods delegated to the singleton instance.
282
- DELEGATES = %i[all each find chat_models embedding_models
272
+ DELEGATES = %i[all each find where chat_models embedding_models
283
273
  audio_models image_models by_family by_provider
284
274
  refresh!].freeze
285
275
 
@@ -319,19 +309,28 @@ module Ask
319
309
  @models.each(&block)
320
310
  end
321
311
 
322
- # Find a model by ID, optionally scoped to a provider.
312
+ # Find a single model by ID. Scopes to provider when given.
323
313
  # @param model_id [String] model identifier
324
- # @param provider [String, nil] provider slug
314
+ # @param provider [String, nil] provider slug (optional keyword)
325
315
  # @return [Ask::ModelInfo]
326
- # @raise [ModelNotFound] if the model is not found
327
- def find(model_id, provider = nil)
316
+ # @raise [ModelNotFound] if no matching model is found
317
+ def find(model_id, provider: nil)
328
318
  if provider
329
- find_with_provider(model_id, provider.to_s)
319
+ @models.find { |m| m.id == model_id && m.provider == provider.to_s } ||
320
+ raise(ModelNotFound, "Model #{model_id.inspect} not found for provider #{provider.inspect}.")
330
321
  else
331
- find_without_provider(model_id)
322
+ @models.find { |m| m.id == model_id } ||
323
+ raise(ModelNotFound, "Unknown model: #{model_id.inspect}.")
332
324
  end
333
325
  end
334
326
 
327
+ # Find all models matching an ID. Never raises.
328
+ # @param model_id [String] model identifier
329
+ # @return [Array<Ask::ModelInfo>] matching models (empty if none)
330
+ def where(model_id)
331
+ @models.select { |m| m.id == model_id }
332
+ end
333
+
335
334
  # @return [Ask::ModelCatalog] new catalog containing only chat models
336
335
  def chat_models
337
336
  self.class.new(@models.select(&:chat?))
@@ -391,31 +390,6 @@ module Ask
391
390
 
392
391
  private
393
392
 
394
- def find_with_provider(model_id, provider)
395
- exact = @models.find { |m| m.id == model_id && m.provider == provider }
396
- return exact if exact
397
-
398
- @models.find { |m| m.id == model_id && m.provider == provider } ||
399
- raise(ModelNotFound, "Model #{model_id.inspect} not found for provider #{provider.inspect}. " \
400
- "Try ModelCatalog.refresh! to update the catalog.")
401
- end
402
-
403
- def find_without_provider(model_id)
404
- matches = @models.select { |m| m.id == model_id }
405
- return preferred_match(matches) if matches.any?
406
-
407
- raise ModelNotFound, "Unknown model: #{model_id.inspect}. " \
408
- "Try ModelCatalog.refresh! to update the catalog."
409
- end
410
-
411
- def preferred_match(candidates)
412
- return candidates.first if candidates.size == 1
413
-
414
- candidates.min_by do |model|
415
- PROVIDER_PREFERENCE.index(model.provider) || PROVIDER_PREFERENCE.length
416
- end
417
- end
418
-
419
393
  def fetch_from_models_dev(timeout: 10)
420
394
  uri = URI(MODELS_DEV_URL)
421
395
  http = Net::HTTP.new(uri.host, uri.port)
data/lib/ask/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ask
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ask-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaka Ruto