Skip to content

Commit 50ef45a

Browse files
committed
Try to make model capabilities more robust. Add to model update task
1 parent bf47c2c commit 50ef45a

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

lib/ruby_llm/providers/mistral/capabilities.rb

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,34 @@ def output_price_for(model_id)
5353
def supports_vision?(model_id)
5454
# Explicitly match the known vision-capable models
5555
vision_models = [
56-
'pixtral-12b-latest',
57-
'pixtral-large-latest',
58-
'mistral-medium-latest',
59-
'mistral-small-latest'
56+
'pixtral-12b',
57+
'pixtral-large',
58+
'mistral-medium',
59+
'mistral-small'
6060
]
61-
vision_models.any? { |id| model_id.include?(id) }
61+
model_id = model_id.to_s.split('/').last
62+
result = vision_models.any? { |id| model_id.match?(/^#{Regexp.escape(id)}/) }
63+
result
6264
end
6365

6466
# Determines if the model supports function calling
6567
# @param model_id [String] the model identifier
6668
# @return [Boolean] true if the model supports functions
6769
def supports_functions?(model_id)
68-
!model_id.match?(/embed|moderation/)
70+
function_calling_models = [
71+
'mistral-large',
72+
'mistral-medium',
73+
'mistral-small',
74+
'codestral',
75+
'ministral-8b',
76+
'ministral-3b',
77+
'pixtral-12b',
78+
'pixtral-large',
79+
'mistral-nemo'
80+
]
81+
model_id = model_id.to_s.split('/').last
82+
result = function_calling_models.any? { |id| model_id.match?(/^#{Regexp.escape(id)}/) }
83+
result
6984
end
7085

7186
# Determines if the model supports audio input/output
@@ -168,6 +183,14 @@ def apply_special_formatting(name)
168183
.gsub("Mathstral ", "Mathstral-")
169184
.gsub("Embed ", "Embed-")
170185
end
186+
187+
def capabilities_for(model_id)
188+
capabilities = ['streaming']
189+
capabilities << 'function_calling' if supports_functions?(model_id)
190+
capabilities << 'structured_output' if supports_json_mode?(model_id)
191+
# Add more as needed (e.g., 'batch', 'caching', etc.)
192+
capabilities
193+
end
171194
end
172195
end
173196
end

lib/ruby_llm/providers/mistral/models.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ def parse_model(model, slug, capabilities)
3333
},
3434
context_window: capabilities.context_window_for(id),
3535
max_tokens: capabilities.max_tokens_for(id),
36-
supports_vision: capabilities.supports_vision?(id),
37-
supports_functions: capabilities.supports_functions?(id),
38-
supports_json_mode: capabilities.supports_json_mode?(id),
39-
input_price_per_million: capabilities.input_price_for(id),
40-
output_price_per_million: capabilities.output_price_for(id),
36+
capabilities: capabilities.capabilities_for(id),
4137
)
4238
end
4339
end

lib/tasks/models_update.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def configure_from_env
2323
config.gemini_api_key = ENV.fetch('GEMINI_API_KEY', nil)
2424
config.deepseek_api_key = ENV.fetch('DEEPSEEK_API_KEY', nil)
2525
config.openrouter_api_key = ENV.fetch('OPENROUTER_API_KEY', nil)
26+
config.mistral_api_key = ENV.fetch('MISTRAL_API_KEY', nil)
2627
configure_bedrock(config)
2728
config.request_timeout = 30
2829
end

0 commit comments

Comments
 (0)