Module: Smith::Models

Extended by:
Dry::Container::Mixin, ProviderQualifiedRegistry
Defined in:
lib/smith/models.rb,
lib/smith/models/profile.rb,
lib/smith/models/inference.rb,
lib/smith/models/normalizer.rb,
lib/smith/models/tool_routing.rb,
lib/smith/models/collision_error.rb,
lib/smith/models/ambiguous_profile_error.rb,
lib/smith/models/provider_qualified_registry.rb

Overview

Capability registry for model ids. Decoupled from Smith.config.pricing (per-installation billing) — this catalog describes payload-shape capabilities (thinking encoding, temperature acceptance, endpoint preferences for tools+thinking).

The library ships NO specific model_id declarations. Smith::Models::Inference provides PATTERN-BASED PROVIDER RULES that match model_ids at runtime (e.g., "Anthropic Opus 4.7+ uses adaptive thinking"). Applications register explicit Profile overrides via Smith::Models.register ONLY when they have a custom model that diverges from its provider's default behavior.

Resolution order in find_or_infer(model_id):

1. Application-registered explicit Profile (override wins)
2. Library Inference rule match
3. Safe default (no thinking, accepts temp, no routing)

Defined Under Namespace

Modules: Inference, ProviderQualifiedRegistry Classes: AmbiguousProfileError, CollisionError, Normalizer, Profile, ToolRouting

Class Method Summary collapse

Methods included from ProviderQualifiedRegistry

all, clear!, extended, find, register

Class Method Details

.find_or_infer(model_id, provider: nil) ⇒ Object

Application overrides first, then Inference rules, then safe default.



35
36
37
# File 'lib/smith/models.rb', line 35

def self.find_or_infer(model_id, provider: nil)
  find(model_id, provider:) || infer(model_id, provider:)
end

.guess_provider(model_id) ⇒ Object



72
73
74
75
76
# File 'lib/smith/models.rb', line 72

def self.guess_provider(model_id)
  key = normalize_key(model_id)
  PROVIDER_PATTERNS.each { |provider, pattern| return provider if key.match?(pattern) }
  :unknown
end

.infer(model_id, provider: nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/smith/models.rb', line 39

def self.infer(model_id, provider: nil)
  inferred = Inference.profile_for(model_id) if defined?(Inference)
  return inferred_profile_for_provider(inferred, provider) if inferred

  Profile.new(
    model_id: normalize_key(model_id),
    provider: provider || guess_provider(model_id),
    thinking_shape: nil,
    accepts_temperature: true,
    tools_with_thinking_native: false,
    tools_with_thinking_route: nil
  )
end

.normalize_key(model_id) ⇒ Object



30
31
32
# File 'lib/smith/models.rb', line 30

def self.normalize_key(model_id)
  model_id.to_s
end