Module: RubyLLM::Providers::Mistral::Models

Included in:
ChatCompletions, VertexAI::Mistral
Defined in:
lib/ruby_llm/providers/mistral/models.rb

Overview

Model information for Mistral

Constant Summary collapse

CAPABILITY_FLAGS =

Mistral's capability flags, named as Models::Schema::CAPABILITIES names.

{
  'function_calling' => 'function_calling',
  'reasoning' => 'reasoning',
  'fine_tuning' => 'fine_tuning',
  'vision' => 'vision',
  'ocr' => 'vision',
  'moderation' => 'moderation',
  'audio_transcription' => 'transcription',
  'audio_transcription_realtime' => 'realtime',
  'audio_speech' => 'speech_generation'
}.freeze

Class Method Summary collapse

Class Method Details

.capabilities_from(flags) ⇒ Object



51
52
53
# File 'lib/ruby_llm/providers/mistral/models.rb', line 51

def capabilities_from(flags)
  CAPABILITY_FLAGS.filter_map { |flag, capability| capability if flags[flag] }
end

.embedding_model?(model_data) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
# File 'lib/ruby_llm/providers/mistral/models.rb', line 66

def embedding_model?(model_data)
  values = [model_data['id'], model_data['description'], *Array(model_data['aliases'])]
  values.any? { |value| value.to_s.match?(/(?:\A|[-_ ])embed(?:ding)?(?:\z|[-_ ])/i) }
end

.metadata_from(model_data) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/ruby_llm/providers/mistral/models.rb', line 71

def (model_data)
  {
    object: model_data['object'],
    owned_by: model_data['owned_by'],
    description: model_data['description'],
    aliases: model_data['aliases'],
    deprecation: model_data['deprecation'],
    deprecation_replacement_model: model_data['deprecation_replacement_model']
  }.reject { |_, value| value.nil? || (value.respond_to?(:empty?) && value.empty?) }
end

.modalities_from(flags, model_data) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/ruby_llm/providers/mistral/models.rb', line 55

def modalities_from(flags, model_data)
  return { input: ['text'], output: ['embeddings'] } if embedding_model?(model_data)
  return { input: ['audio'], output: ['text'] } if flags['audio_transcription']

  input = ['text']
  input << 'image' if flags['vision'] || flags['ocr']
  output = ['text']
  output << 'audio' if flags['audio_speech']
  { input: input, output: output }
end

.models_dev_alias(model_id, models_dev_by_key, provider_model = nil) ⇒ Object



27
28
29
30
31
32
# File 'lib/ruby_llm/providers/mistral/models.rb', line 27

def models_dev_alias(model_id, models_dev_by_key, provider_model = nil)
  source = Array(provider_model&.&.[](:aliases)).filter_map do |alias_id|
    models_dev_by_key["mistral:#{alias_id}"]
  end.first
  Model.new(source.to_h.merge(id: model_id)) if source
end

.models_urlObject



23
24
25
# File 'lib/ruby_llm/providers/mistral/models.rb', line 23

def models_url
  'models'
end

.parse_list_models_response(response, slug) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby_llm/providers/mistral/models.rb', line 34

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

    Model.new(
      id: model_id,
      name: model_id,
      provider: slug,
      context_window: model_data['max_context_length'],
      modalities: modalities_from(flags, model_data),
      capabilities: capabilities_from(flags),
      metadata: (model_data)
    )
  end
end