Class: Ace::Support::Models::Atoms::ModelNameCanonicalizer
- Inherits:
-
Object
- Object
- Ace::Support::Models::Atoms::ModelNameCanonicalizer
- 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
-
.canonicalize(model_id, provider: nil) ⇒ String
Extract the canonical model name by stripping provider-specific suffixes.
-
.extract_suffix(model_id) ⇒ String?
Extract the suffix from a model ID if present.
-
.has_suffix?(model_id, provider: nil) ⇒ Boolean
Check if a model ID has a known suffix for the given provider.
-
.suffixes_for(provider) ⇒ Array<String>
Get all known suffixes for a provider.
Class Method Details
.canonicalize(model_id, provider: nil) ⇒ String
Extract the canonical model name by stripping provider-specific suffixes
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
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
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
96 97 98 |
# File 'lib/ace/support/models/atoms/model_name_canonicalizer.rb', line 96 def suffixes_for(provider) PROVIDER_SUFFIXES[provider] || [] end |