Module: RubyLLM::Agents::Audio::ElevenLabs::ModelRegistry
- Extended by:
- ModelRegistry
- Included in:
- ModelRegistry
- Defined in:
- lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb
Overview
Fetches and caches ElevenLabs model data from the /v1/models API.
Used for:
-
Dynamic cost calculation via character_cost_multiplier
-
Model validation (TTS vs STS capability)
-
Capability awareness (style, speaker_boost, max chars, languages)
Instance Method Summary collapse
-
#clear_cache! ⇒ void
Clear cache without re-fetching (useful for tests).
-
#cost_multiplier(model_id) ⇒ Float
Get character_cost_multiplier for a model.
-
#find(model_id) ⇒ Hash?
Find a specific model by ID.
-
#languages(model_id) ⇒ Array<String>
Get supported language IDs for a model.
-
#max_characters(model_id) ⇒ Integer?
Get max characters per request for a model.
-
#models ⇒ Array<Hash>
Returns all models from the ElevenLabs API (cached).
-
#refresh! ⇒ Array<Hash>
Force refresh the cache.
-
#supports_speaker_boost?(model_id) ⇒ Boolean
Check if model supports the speaker_boost setting.
-
#supports_style?(model_id) ⇒ Boolean
Check if model supports the style voice setting.
-
#tts_model?(model_id) ⇒ Boolean
Check if model supports text-to-speech.
-
#voice_conversion_model?(model_id) ⇒ Boolean
Check if model supports voice conversion (speech-to-speech) Used by VoiceConverter agent (see plans/elevenlabs_voice_converter.md).
Instance Method Details
#clear_cache! ⇒ void
This method returns an undefined value.
Clear cache without re-fetching (useful for tests)
132 133 134 135 136 137 138 |
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 132 def clear_cache! @mutex ||= Mutex.new @mutex.synchronize do @models = nil @fetched_at = nil end end |
#cost_multiplier(model_id) ⇒ Float
Get character_cost_multiplier for a model
66 67 68 69 |
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 66 def cost_multiplier(model_id) model = find(model_id) model&.dig("model_rates", "character_cost_multiplier") || 1.0 end |
#find(model_id) ⇒ Hash?
Find a specific model by ID
47 48 49 |
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 47 def find(model_id) models.find { |m| m["model_id"] == model_id.to_s } end |
#languages(model_id) ⇒ Array<String>
Get supported language IDs for a model
84 85 86 87 |
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 84 def languages(model_id) model = find(model_id) model&.dig("languages")&.map { |l| l["language_id"] } || [] end |
#max_characters(model_id) ⇒ Integer?
Get max characters per request for a model
75 76 77 78 |
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 75 def max_characters(model_id) model = find(model_id) model&.dig("maximum_text_length_per_request") end |
#models ⇒ Array<Hash>
Returns all models from the ElevenLabs API (cached)
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 30 def models @mutex ||= Mutex.new @mutex.synchronize do if @models && !cache_expired? return @models end @models = fetch_models @fetched_at = Time.now @models end end |
#refresh! ⇒ Array<Hash>
Force refresh the cache
120 121 122 123 124 125 126 127 |
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 120 def refresh! @mutex ||= Mutex.new @mutex.synchronize do @models = nil @fetched_at = nil end models end |
#supports_speaker_boost?(model_id) ⇒ Boolean
Check if model supports the speaker_boost setting
101 102 103 |
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 101 def supports_speaker_boost?(model_id) find(model_id)&.dig("can_use_speaker_boost") == true end |
#supports_style?(model_id) ⇒ Boolean
Check if model supports the style voice setting
93 94 95 |
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 93 def supports_style?(model_id) find(model_id)&.dig("can_use_style") == true end |
#tts_model?(model_id) ⇒ Boolean
Check if model supports text-to-speech
55 56 57 58 59 60 |
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 55 def tts_model?(model_id) model = find(model_id) return false unless model model["can_do_text_to_speech"] == true end |
#voice_conversion_model?(model_id) ⇒ Boolean
Check if model supports voice conversion (speech-to-speech) Used by VoiceConverter agent (see plans/elevenlabs_voice_converter.md)
110 111 112 113 114 115 |
# File 'lib/ruby_llm/agents/audio/elevenlabs/model_registry.rb', line 110 def voice_conversion_model?(model_id) model = find(model_id) return false unless model model["can_do_voice_conversion"] == true end |