Module: RubyLLM::Protocols::Deepgram::Models
- Defined in:
- lib/ruby_llm/protocols/deepgram/models.rb
Overview
Model catalog for Deepgram. GET v1/models splits the catalog into
stt and tts groups, and names each entry twice: name is the short
name, such as the voice 'zeus', while canonical_name is the id the
listen and speak endpoints accept.
Class Method Summary collapse
- .build_metadata(data) ⇒ Object
- .build_model(data, slug, group) ⇒ Object
-
.merge_language_rows(rows) ⇒ Object
Deepgram lists a model once per language it was trained on, so nova-3-general arrives 146 times with a different language and version each time.
- .models_url ⇒ Object
- .parse_list_models_response(response, slug) ⇒ Object
Class Method Details
.build_metadata(data) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ruby_llm/protocols/deepgram/models.rb', line 61 def (data) = { architecture: data['architecture'], languages: data['languages'], version: data['version'] } [:voice] = data['name'] if data['name'] && data['name'] != data['canonical_name'] .merge!(data['metadata'].transform_keys(&:to_sym)) if data['metadata'].is_a?(Hash) .compact end |
.build_model(data, slug, group) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ruby_llm/protocols/deepgram/models.rb', line 40 def build_model(data, slug, group) model_id = data['canonical_name'] || data['name'] transcription = group == 'stt' && !model_id.start_with?('flux-') modalities = if group == 'stt' { input: ['audio'], output: ['text'] } else { input: ['text'], output: ['audio'] } end Model.new( id: model_id, name: model_id, provider: slug, family: data['architecture'], modalities: modalities, capabilities: transcription ? ['transcription'] : [], pricing: {}, metadata: (data) ) end |
.merge_language_rows(rows) ⇒ Object
Deepgram lists a model once per language it was trained on, so nova-3-general arrives 146 times with a different language and version each time. One model answers to that id, so the rows collapse into it, carrying every language between them. Fields the rows disagree on describe a single language rather than the model, and are left out.
32 33 34 35 36 37 38 |
# File 'lib/ruby_llm/protocols/deepgram/models.rb', line 32 def merge_language_rows(rows) merged = rows.first.merge('languages' => rows.flat_map { |row| Array(row['languages']) }.uniq.sort) %w[version architecture].each do |key| merged.delete(key) unless rows.map { |row| row[key] }.uniq.one? end merged end |
.models_url ⇒ Object
13 14 15 |
# File 'lib/ruby_llm/protocols/deepgram/models.rb', line 13 def models_url 'v1/models' end |
.parse_list_models_response(response, slug) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/ruby_llm/protocols/deepgram/models.rb', line 17 def parse_list_models_response(response, slug) body = response.body || {} %w[stt tts].flat_map do |group| Array(body[group]).group_by { |data| data['canonical_name'] || data['name'] } .map { |_, rows| build_model(merge_language_rows(rows), slug, group) } end end |