Module: RubyLLM::Resilience::TierNamer
- Defined in:
- lib/ruby_llm/resilience/tier_namer.rb
Overview
Default service_namer: maps a model name to a per-provider, per-TIER breaker name ("api:anthropic:sonnet").
Tier-level (not per-model) breakers are deliberate: provider capacity incidents are tier-correlated (when Sonnet is overloaded, every Sonnet version typically is), and a version rollover (sonnet-4-5 → sonnet-4-6) shouldn't fragment health state across two breakers.
Custom naming is one lambda away:
config.service_namer = ->(model) { "api:#{model}" } # per-model
Class Method Summary collapse
- .anthropic(model_name) ⇒ Object
- .call(model_name) ⇒ Object
-
.google(model_name) ⇒ Object
Order matters — flash-lite must be tested before flash, since "gemini-3.1-flash-lite" matches both /flash/ and /flash-lite/.
-
.openai(model_name) ⇒ Object
Order matters —
-nano/-mini/-promust be tested before the bare^gptmatch (gpt-5.5-pro matches both-proand^gpt).
Class Method Details
.anthropic(model_name) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/ruby_llm/resilience/tier_namer.rb', line 29 def anthropic(model_name) case model_name.to_s when /haiku/ then "api:anthropic:haiku" when /sonnet/ then "api:anthropic:sonnet" when /opus/ then "api:anthropic:opus" else "api:anthropic:other" end end |
.call(model_name) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby_llm/resilience/tier_namer.rb', line 18 def call(model_name) provider = Resilience.config.provider_resolver.call(model_name).to_s case provider when "anthropic" then anthropic(model_name) when "gemini", "google" then google(model_name) when "openai" then openai(model_name) else "api:unknown:other" end end |
.google(model_name) ⇒ Object
Order matters — flash-lite must be tested before flash, since "gemini-3.1-flash-lite" matches both /flash/ and /flash-lite/.
40 41 42 43 44 45 46 47 |
# File 'lib/ruby_llm/resilience/tier_namer.rb', line 40 def google(model_name) case model_name.to_s when /flash-lite/ then "api:google:flash-lite" when /flash/ then "api:google:flash" when /pro/ then "api:google:pro" else "api:google:other" end end |
.openai(model_name) ⇒ Object
Order matters — -nano / -mini / -pro must be tested before the
bare ^gpt match (gpt-5.5-pro matches both -pro and ^gpt).
51 52 53 54 55 56 57 58 59 |
# File 'lib/ruby_llm/resilience/tier_namer.rb', line 51 def openai(model_name) case model_name.to_s when /-nano/ then "api:openai:gpt-nano" when /-mini/ then "api:openai:gpt-mini" when /-pro/ then "api:openai:gpt-pro" when /^gpt/ then "api:openai:gpt" else "api:openai:other" end end |