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.

Constant Summary collapse

IMAGE_MODELS =
%w[grok-2-image-1212].freeze
VISION_MODELS =
%w[
  grok-2-vision-1212
  grok-4-0709
  grok-4-fast-non-reasoning
  grok-4-fast-reasoning
  grok-4-1-fast-non-reasoning
  grok-4-1-fast-reasoning
].freeze
REASONING_MODELS =
%w[
  grok-3-mini
  grok-4-0709
  grok-4-fast-reasoning
  grok-4-1-fast-reasoning
  grok-code-fast-1
].freeze

Class Method Summary collapse

Class Method Details

.capabilities_for(model_id) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/ruby_llm/providers/xai/models.rb', line 60

def capabilities_for(model_id)
  return [] if IMAGE_MODELS.include?(model_id)

  capabilities = %w[streaming function_calling structured_output]
  capabilities << 'reasoning' if REASONING_MODELS.include?(model_id)
  capabilities << 'vision' if VISION_MODELS.include?(model_id)
  capabilities
end

.format_display_name(model_id) ⇒ Object



69
70
71
# File 'lib/ruby_llm/providers/xai/models.rb', line 69

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

.modalities_for(model_id) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/ruby_llm/providers/xai/models.rb', line 50

def modalities_for(model_id)
  if IMAGE_MODELS.include?(model_id)
    { input: ['text'], output: ['image'] }
  else
    input = ['text']
    input << 'image' if VISION_MODELS.include?(model_id)
    { input: input, output: ['text'] }
  end
end

.parse_list_models_response(response, slug, _capabilities) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ruby_llm/providers/xai/models.rb', line 27

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