Class: RosettAi::AiConfig::ModelRouter
- Inherits:
-
Object
- Object
- RosettAi::AiConfig::ModelRouter
- Defined in:
- lib/rosett_ai/ai_config/model_router.rb
Overview
Maps canonical model tiers to engine-specific model identifiers.
Supports three standard tiers (economy, standard, premium) plus custom model names. Engine manifests declare their model mappings. Use ModelRouter.with_manifest_mappings to load mappings from installed engines.
Constant Summary collapse
- CANONICAL_TIERS =
['economy', 'standard', 'premium'].freeze
- DEFAULT_MAPPINGS =
Default model mappings per engine (used when engine manifest unavailable).
{ 'claude' => { 'economy' => 'claude-haiku-4-5-20251001', 'standard' => 'claude-sonnet-4-5-20250929', 'premium' => 'claude-opus-4-6' }, 'ollama' => { 'economy' => 'llama3.2:3b', 'standard' => 'llama3.3:8b', 'premium' => 'llama3.3:70b' } }.freeze
Class Method Summary collapse
-
.with_manifest_mappings(extra_mappings: {}) ⇒ ModelRouter
Builds a ModelRouter that merges manifest-declared model mappings from installed engines with DEFAULT_MAPPINGS.
Instance Method Summary collapse
-
#available_tiers(engine) ⇒ Array<String>
Lists all available tiers for an engine.
-
#engine_supported?(engine) ⇒ Boolean
True if engine has model mappings.
-
#initialize(custom_mappings: {}) ⇒ ModelRouter
constructor
A new instance of ModelRouter.
-
#resolve(tier, engine:) ⇒ String
Resolves a canonical tier to an engine-specific model ID.
-
#resolve_all(tier) ⇒ Hash<String, String>
Resolves a canonical tier across all known engines.
Constructor Details
#initialize(custom_mappings: {}) ⇒ ModelRouter
Returns a new instance of ModelRouter.
44 45 46 |
# File 'lib/rosett_ai/ai_config/model_router.rb', line 44 def initialize(custom_mappings: {}) @mappings = DEFAULT_MAPPINGS.merge(custom_mappings) end |
Class Method Details
.with_manifest_mappings(extra_mappings: {}) ⇒ ModelRouter
Builds a ModelRouter that merges manifest-declared model mappings from installed engines with DEFAULT_MAPPINGS.
38 39 40 41 |
# File 'lib/rosett_ai/ai_config/model_router.rb', line 38 def self.with_manifest_mappings(extra_mappings: {}) manifest_mappings = load_manifest_mappings new(custom_mappings: manifest_mappings.merge(extra_mappings)) end |
Instance Method Details
#available_tiers(engine) ⇒ Array<String>
Lists all available tiers for an engine.
69 70 71 72 |
# File 'lib/rosett_ai/ai_config/model_router.rb', line 69 def available_tiers(engine) engine_map = @mappings.fetch(engine, {}) engine_map.keys end |
#engine_supported?(engine) ⇒ Boolean
Returns true if engine has model mappings.
76 77 78 |
# File 'lib/rosett_ai/ai_config/model_router.rb', line 76 def engine_supported?(engine) @mappings.key?(engine) end |
#resolve(tier, engine:) ⇒ String
Resolves a canonical tier to an engine-specific model ID.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rosett_ai/ai_config/model_router.rb', line 54 def resolve(tier, engine:) return extract_custom_model(tier) if tier.start_with?('custom:') validate_tier!(tier) engine_map = @mappings.fetch(engine, {}) engine_map.fetch(tier) do raise RosettAi::AiConfigError, "No model mapping for tier '#{tier}' on engine '#{engine}'" end end |
#resolve_all(tier) ⇒ Hash<String, String>
Resolves a canonical tier across all known engines.
84 85 86 87 88 89 |
# File 'lib/rosett_ai/ai_config/model_router.rb', line 84 def resolve_all(tier) validate_tier!(tier) @mappings.each_with_object({}) do |(engine, map), result| result[engine] = map[tier] if map.key?(tier) end end |