Module: RubyLLM::Providers::XAI::Models

Included in:
RubyLLM::Providers::XAI
Defined in:
lib/ruby_llm/providers/xai/models.rb

Overview

Models metadata for xAI list models.

Class Method Summary collapse

Class Method Details

.capabilities_for(model_id) ⇒ Object



43
44
45
46
47
# File 'lib/ruby_llm/providers/xai/models.rb', line 43

def capabilities_for(model_id)
  return ['vision'] if image_model?(model_id) || video_model?(model_id)

  ['streaming']
end

.format_display_name(model_id) ⇒ Object



49
50
51
# File 'lib/ruby_llm/providers/xai/models.rb', line 49

def format_display_name(model_id)
  model_id.tr('-', ' ').split.map(&:capitalize).join(' ')
end

.image_model?(model_id) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/ruby_llm/providers/xai/models.rb', line 53

def image_model?(model_id)
  model_id.match?(/\Agrok-(?:2-)?imagine-image/) || model_id == 'grok-2-image-1212'
end

.modalities_for(model_id) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/ruby_llm/providers/xai/models.rb', line 33

def modalities_for(model_id)
  if image_model?(model_id)
    { input: %w[text image], output: ['image'] }
  elsif video_model?(model_id)
    { input: %w[text image video], output: ['video'] }
  else
    { input: ['text'], output: ['text'] }
  end
end

.parse_list_models_response(response, slug, _capabilities) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby_llm/providers/xai/models.rb', line 10

def parse_list_models_response(response, slug, _capabilities)
  Array(response.body['data']).map do |model_data|
    model_id = model_data['id']

    Model::Info.new(
      id: model_id,
      name: format_display_name(model_id),
      provider: slug,
      family: 'grok',
      created_at: model_data['created'] ? Time.at(model_data['created']) : nil,
      context_window: nil,
      max_output_tokens: nil,
      modalities: modalities_for(model_id),
      capabilities: capabilities_for(model_id),
      pricing: {},
      metadata: {
        object: model_data['object'],
        owned_by: model_data['owned_by']
      }.compact
    )
  end
end

.video_model?(model_id) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/ruby_llm/providers/xai/models.rb', line 57

def video_model?(model_id)
  model_id.match?(/\Agrok-(?:2-)?imagine-video/)
end