Class: Ace::Support::Models::Atoms::ModelNameCanonicalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/models/atoms/model_name_canonicalizer.rb

Overview

Canonicalizes model names by stripping provider-specific suffixes

OpenRouter uses dynamic and static suffixes that modify routing behavior but don’t represent different models in the canonical model registry.

Constant Summary collapse

OPENROUTER_DYNAMIC_SUFFIXES =

OpenRouter dynamic suffixes (work across all models, modify routing)

%w[
  nitro
  floor
  online
].freeze
OPENROUTER_STATIC_SUFFIXES =

OpenRouter static suffixes (apply to specific models only)

%w[
  free
  extended
  exacto
  thinking
].freeze
OPENROUTER_SUFFIXES =

Combined list of all known OpenRouter suffixes

(OPENROUTER_DYNAMIC_SUFFIXES + OPENROUTER_STATIC_SUFFIXES).freeze
PROVIDER_SUFFIXES =

Provider-specific suffix configurations Maps provider ID to array of suffixes to strip

{
  "openrouter" => OPENROUTER_SUFFIXES
}.freeze

Class Method Summary collapse

Class Method Details

.canonicalize(model_id, provider: nil) ⇒ String

Extract the canonical model name by stripping provider-specific suffixes

Examples:

Strip OpenRouter :nitro suffix

canonicalize("openai/gpt-4:nitro", provider: "openrouter")
# => "openai/gpt-4"

Preserve model with no suffix

canonicalize("openai/gpt-4", provider: "openrouter")
# => "openai/gpt-4"

Non-OpenRouter provider keeps suffix

canonicalize("model:variant", provider: "other")
# => "model:variant"

Parameters:

  • model_id (String)

    The model ID (e.g., “openai/gpt-4:nitro”)

  • provider (String, nil) (defaults to: nil)

    The provider ID to determine which suffixes to strip

Returns:

  • (String)

    The canonical model name (e.g., “openai/gpt-4”)



56
57
58
59
60
61
62
63
# File 'lib/ace/support/models/atoms/model_name_canonicalizer.rb', line 56

def canonicalize(model_id, provider: nil)
  return model_id if model_id.nil? || model_id.empty?

  suffixes = PROVIDER_SUFFIXES[provider]
  return model_id unless suffixes

  strip_suffixes(model_id, suffixes)
end

.extract_suffix(model_id) ⇒ String?

Extract the suffix from a model ID if present

Parameters:

  • model_id (String)

    The model ID

Returns:

  • (String, nil)

    The suffix without the colon, or nil if no suffix



84
85
86
87
88
89
90
# File 'lib/ace/support/models/atoms/model_name_canonicalizer.rb', line 84

def extract_suffix(model_id)
  return nil if model_id.nil? || model_id.empty?

  # Match the last :suffix pattern (handles model IDs like "org/model:suffix")
  match = model_id.match(/:([^:\/]+)$/)
  match&.captures&.first
end

.has_suffix?(model_id, provider: nil) ⇒ Boolean

Check if a model ID has a known suffix for the given provider

Parameters:

  • model_id (String)

    The model ID to check

  • provider (String, nil) (defaults to: nil)

    The provider ID

Returns:

  • (Boolean)

    true if the model has a strippable suffix



70
71
72
73
74
75
76
77
78
# File 'lib/ace/support/models/atoms/model_name_canonicalizer.rb', line 70

def has_suffix?(model_id, provider: nil)
  return false if model_id.nil? || model_id.empty?

  suffixes = PROVIDER_SUFFIXES[provider]
  return false unless suffixes

  suffix = extract_suffix(model_id)
  suffix && suffixes.include?(suffix)
end

.suffixes_for(provider) ⇒ Array<String>

Get all known suffixes for a provider

Parameters:

  • provider (String)

    The provider ID

Returns:

  • (Array<String>)

    Array of suffix strings (without colons)



96
97
98
# File 'lib/ace/support/models/atoms/model_name_canonicalizer.rb', line 96

def suffixes_for(provider)
  PROVIDER_SUFFIXES[provider] || []
end