Module: RubyLLM::Protocols::ElevenLabs::Models

Defined in:
lib/ruby_llm/protocols/elevenlabs/models.rb

Overview

Model catalog for ElevenLabs. GET v1/models returns a bare array of the speech synthesis models and leaves out the Scribe transcription models, so those are appended from the published catalog.

Constant Summary collapse

TRANSCRIPTION_MODELS =
{
  'scribe_v2' => 'Scribe v2',
  'scribe_v2_realtime' => 'Scribe v2 Realtime'
}.freeze

Class Method Summary collapse

Class Method Details

.build_model(model_id, slug, name: nil, description: nil, data: {}, transcription: false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ruby_llm/protocols/elevenlabs/models.rb', line 32

def build_model(model_id, slug, name: nil, description: nil, data: {}, transcription: false)
  transcription ||= TRANSCRIPTION_MODELS.key?(model_id)

  Model.new(
    id: model_id,
    name: name || model_id,
    provider: slug,
    family: transcription ? 'scribe' : 'eleven',
    modalities: modalities_for(data, transcription),
    capabilities: capabilities_from(data, transcription),
    pricing: {},
    metadata: { description: description }.compact
  )
end

.capabilities_from(data, transcription) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/ruby_llm/protocols/elevenlabs/models.rb', line 54

def capabilities_from(data, transcription)
  capabilities = []
  capabilities << 'transcription' if transcription
  capabilities << 'speech_generation' if data['can_do_text_to_speech']
  capabilities << 'fine_tuning' if data['can_be_finetuned']
  capabilities
end

.modalities_for(data, transcription) ⇒ Object



47
48
49
50
51
52
# File 'lib/ruby_llm/protocols/elevenlabs/models.rb', line 47

def modalities_for(data, transcription)
  return { input: ['audio'], output: ['text'] } if transcription
  return { input: ['audio'], output: ['audio'] } if data['can_do_voice_conversion']

  { input: ['text'], output: ['audio'] }
end

.models_urlObject



17
18
19
# File 'lib/ruby_llm/protocols/elevenlabs/models.rb', line 17

def models_url
  'v1/models'
end

.parse_list_models_response(response, slug) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/ruby_llm/protocols/elevenlabs/models.rb', line 21

def parse_list_models_response(response, slug)
  listed = Array(response.body).map do |data|
    build_model(data['model_id'], slug, name: data['name'], description: data['description'], data: data)
  end
  listed_ids = listed.map(&:id)

  listed + TRANSCRIPTION_MODELS.except(*listed_ids).map do |model_id, name|
    build_model(model_id, slug, name: name, transcription: true)
  end
end