classifier 2.5.0 → 2.6.0

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: 539130382c7ce45072e515ee9817f47fb1144af18498a81c27c7dda842477141
4
- data.tar.gz: 1537f2c7c164ec70c14c7b314148fa81cfb947a93dfe328125082567c5a99a7e
3
+ metadata.gz: 527f52e23121cbda5ce138a74c200f473813ea306aa04f50bd74f2d1230ff45b
4
+ data.tar.gz: ca52b0412149e3e6bf3d885d12ef5485ab1a70d6dcc4cb659121733bfcced2da
5
5
  SHA512:
6
- metadata.gz: 3bf1385063c020bb08097192417232a6dc3fce7a16a057bec27ccf62253d69809fedc692f597b7ab6c4e36e8236629188e37add798d883ed670a55cb02c37023
7
- data.tar.gz: '0528f07ae03ab30b752c3242b747058956831900c55c1c5a858ab623525075806a52fc8b66236de0f4b959ce678f9a24204887434b19c8662860d06173b2634f'
6
+ metadata.gz: 9ddcb1c5c85229beef3b8b048f65fae551ae97ac032e51f07937470070f48cb2d56adca0bd30df1f981a93e44004e572a258c9ecf7dbfed26f8005ca52247714
7
+ data.tar.gz: 79ffe1a234a988c5d026740405c350f2222a15eaf6a562e4b1da39cf6bdf1aaea43dbfe85bfc55db9830684a10eea3c9f4df0eae4921374fe2d6ac0d4c7b7606
@@ -95,6 +95,13 @@ module Classifier
95
95
  @options[:type] = type
96
96
  end
97
97
 
98
+ opts.on(
99
+ '--search TEXT',
100
+ 'Search remote models by name/description, and local models by name only. Use quotes for multiword search'
101
+ ) do |text|
102
+ @options[:search] = text
103
+ end
104
+
98
105
  opts.on('-r', '--remote MODEL', 'Use remote model: name or @user/repo:name') do |model|
99
106
  @options[:remote] = model
100
107
  end
@@ -370,18 +377,49 @@ module Classifier
370
377
  end
371
378
 
372
379
  def list_remote_models
373
- registry_arg = @args.shift
374
- registry = parse_registry(registry_arg) || DEFAULT_REGISTRY
380
+ registry_or_model_arg = @args.shift
381
+ registry, model = detect_registry_and_model(registry_or_model_arg)
382
+ registry = parse_registry(registry) || DEFAULT_REGISTRY
375
383
  index = fetch_registry_index(registry)
376
384
 
377
385
  return if @exit_code != 0
378
386
 
379
- if index['models'].empty?
387
+ models = index['models']
388
+
389
+ if model
390
+ info = models[model]
391
+ if info.nil?
392
+ @output << "No model #{model.inspect} found in registry"
393
+ return
394
+ end
395
+
396
+ type = info['type'] || 'unknown'
397
+ size = info['size'] || 'unknown'
398
+ desc = info['description'] || ''
399
+ categories = (info['categories'] || []).map(&:downcase).join(', ')
400
+ version = info['version'] || ''
401
+ author = info['author'] || ''
402
+ @output << format(
403
+ "Name: %<name>s\nDescription: %<desc>s\nType: %<type>s\n" \
404
+ "Categories: %<categories>s\nVersion: %<version>s\nAuthor: %<author>s\nSize: %<size>s",
405
+ name: model, desc: desc, type: type, categories: categories,
406
+ version: version, author: author, size: size
407
+ )
408
+ return
409
+ end
410
+
411
+ if @options[:search]
412
+ models = models.filter do |name, info|
413
+ [name, info['description']].any?(/#{Regexp.escape(@options[:search])}/i)
414
+ end
415
+ end
416
+
417
+ if models.empty?
380
418
  @output << 'No models found in registry'
381
419
  return
382
420
  end
383
421
 
384
- index['models'].each do |name, info|
422
+ models.each do |name, info|
385
423
  type = info['type'] || 'unknown'
386
424
  size = info['size'] || 'unknown'
387
425
  desc = info['description'] || ''
@@ -390,6 +428,8 @@ module Classifier
390
428
  end
391
429
 
392
430
  def list_local_models
431
+ model_arg = @args.shift
432
+
393
433
  models_dir = File.join(CACHE_DIR, 'models')
394
434
 
395
435
  unless Dir.exist?(models_dir)
@@ -413,14 +453,43 @@ module Classifier
413
453
 
414
454
  models = default_models + custom_models #: Array[{name: String, registry: String?, path: String}]
415
455
 
456
+ models.each do |model|
457
+ model[:info] = load_model_info(model[:path])
458
+ end
459
+
460
+ if model_arg
461
+ model = models.find { |model| model[:name] == model_arg }
462
+ if model.nil?
463
+ @output << "No local model #{model_arg.inspect} found"
464
+ return
465
+ end
466
+ display_name = model[:registry] ? "@#{model[:registry]}:#{model[:name]}" : model[:name]
467
+ type = model.dig(:info, 'type') || 'unknown'
468
+ version = model.dig(:info, 'version')
469
+ categories = (model.dig(:info, 'categories') || {}).keys.map(&:downcase).join(', ')
470
+ size = File.size(model[:path])
471
+ @output << format(
472
+ "Name: %<name>s\nType: %<type>s\n" \
473
+ "Categories: %<categories>s\nVersion: %<version>s\nSize: %<size>s",
474
+ name: display_name, type: type, categories: categories,
475
+ version: version, size: human_size(size)
476
+ )
477
+ return
478
+ end
479
+
480
+ if @options[:search]
481
+ models = models.filter do |model|
482
+ [model[:name], model.dig(:info, 'description')].any?(/#{Regexp.escape(@options[:search])}/i)
483
+ end
484
+ end
485
+
416
486
  if models.empty?
417
487
  @output << 'No local models found'
418
488
  return
419
489
  end
420
490
 
421
491
  models.each do |model|
422
- info = load_model_info(model[:path])
423
- type = info['type'] || 'unknown'
492
+ type = model.dig(:info, 'type') || 'unknown'
424
493
  display_name = model[:registry] ? "@#{model[:registry]}:#{model[:name]}" : model[:name]
425
494
  size = File.size(model[:path])
426
495
  @output << format('%-30<name>s (%<type>s, %<size>s)', name: display_name, type: type, size: human_size(size))
@@ -800,6 +869,15 @@ module Classifier
800
869
  @output << 'Run "classifier --help" for full usage.'
801
870
  end
802
871
 
872
+ # @rbs (String?) -> [String?, String?]
873
+ def detect_registry_and_model(arg)
874
+ return nil, nil if arg.nil?
875
+ return *arg.split(':', 2) if arg.include?(':')
876
+ return nil, arg unless arg.start_with?('@')
877
+
878
+ [arg, nil]
879
+ end
880
+
803
881
  # Parse @user/repo format to extract registry
804
882
  # @rbs (String?) -> String?
805
883
  def parse_registry(arg)
@@ -1,3 +1,3 @@
1
1
  module Classifier
2
- VERSION = '2.5.0'.freeze
2
+ VERSION = '2.6.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Carlson