Class: Qualspec::ModelRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/qualspec/model_registry.rb

Overview

Loads a curated list of named models from a YAML config file and resolves names to their full provider slugs. Unknown/blank names fall back to the configured default (ultimately Configuration::DEFAULT_MODEL, openrouter/auto), so model lookups always return something usable.

Examples:

config/models.yml

default: openrouter/auto
models:
  glm: z-ai/glm-5.2
Qualspec.model(:glm)      # => "z-ai/glm-5.2"
Qualspec.model(:nope)     # => "openrouter/auto"
Qualspec.model            # => "openrouter/auto"

Constant Summary collapse

DEFAULT_CONFIG_PATH =
'config/models.yml'

Instance Method Summary collapse

Constructor Details

#initialize(path: nil, default: nil) ⇒ ModelRegistry

Returns a new instance of ModelRegistry.



23
24
25
26
27
# File 'lib/qualspec/model_registry.rb', line 23

def initialize(path: nil, default: nil)
  @models = {}
  @default = default
  load_file(path || ENV['QUALSPEC_MODELS_FILE'] || DEFAULT_CONFIG_PATH)
end

Instance Method Details

#allHash{String=>String}

Returns all configured name => slug pairs.

Returns:

  • (Hash{String=>String})

    all configured name => slug pairs



40
41
42
# File 'lib/qualspec/model_registry.rb', line 40

def all
  @models.dup
end

#defaultString

Returns the universal fallback model.

Returns:

  • (String)

    the universal fallback model



45
46
47
# File 'lib/qualspec/model_registry.rb', line 45

def default
  @default || Configuration::DEFAULT_MODEL
end

#resolve(name = nil) ⇒ String

Resolve a model name to its slug, falling back to the default.

Parameters:

  • name (Symbol, String, nil) (defaults to: nil)

    the configured name (or nil for default)

Returns:

  • (String)

    a model slug



33
34
35
36
37
# File 'lib/qualspec/model_registry.rb', line 33

def resolve(name = nil)
  return default if name.nil? || name.to_s.empty?

  @models.fetch(name.to_s, default)
end