Class: Legion::Extensions::Llm::Mlx::Provider
- Inherits:
-
Provider
- Object
- Provider
- Legion::Extensions::Llm::Mlx::Provider
- Includes:
- CapabilityConfig, CapabilityResolution, HealthHelpers, Provider::OpenAICompatible
- Defined in:
- lib/legion/extensions/llm/mlx/provider.rb
Overview
MLX provider implementation for local OpenAI-compatible servers.
Class Method Summary collapse
- .capabilities ⇒ Object
- .configuration_options ⇒ Object
- .configuration_requirements ⇒ Object
- .default_tier ⇒ Object
- .default_transport ⇒ Object
- .local? ⇒ Boolean
- .slug ⇒ Object
Instance Method Summary collapse
- #api_base ⇒ Object
- #headers ⇒ Object
- #health(live: false) ⇒ Object
- #health_url ⇒ Object
- #list_models ⇒ Object
- #offering_from_model(model_info, health: {}) ⇒ Object
- #readiness(live: false) ⇒ Object
- #settings ⇒ Object
Class Method Details
.capabilities ⇒ Object
177 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 177 def capabilities = Capabilities |
.configuration_options ⇒ Object
175 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 175 def = %i[mlx_api_base mlx_api_key] |
.configuration_requirements ⇒ Object
176 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 176 def configuration_requirements = [] |
.default_tier ⇒ Object
174 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 174 def default_tier = :local |
.default_transport ⇒ Object
173 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 173 def default_transport = :http |
.local? ⇒ Boolean
172 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 172 def local? = true |
.slug ⇒ Object
171 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 171 def slug = 'mlx' |
Instance Method Details
#api_base ⇒ Object
184 185 186 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 184 def api_base normalize_url(config.mlx_api_base || settings[:instances][:default][:endpoint]) end |
#headers ⇒ Object
188 189 190 191 192 193 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 188 def headers hdrs = identity_headers token = config.mlx_api_key hdrs['Authorization'] = "Bearer #{token}" unless token.nil? || token.to_s.empty? hdrs end |
#health(live: false) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 197 def health(live: false) log.info("Checking MLX health live=#{live} at #{api_base}#{health_url}") raw = connection.get(health_url).body health_payload(raw) rescue StandardError => e handle_exception(e, level: :warn, handled: true, operation: 'mlx.provider.health') { provider: :mlx, instance_id: provider_instance_id, status: 'unhealthy', ready: false, circuit_state: 'open', error: e.class.name, message: e. } end |
#health_url ⇒ Object
195 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 195 def health_url = '/health' |
#list_models ⇒ Object
219 220 221 222 223 224 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 219 def list_models(**) log.info('Listing available MLX models') models = super log.info("Discovered #{Array(models).size} MLX models") models end |
#offering_from_model(model_info, health: {}) ⇒ Object
226 227 228 229 230 231 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 226 def offering_from_model(model_info, health: {}) policy = resolve_capability_policy(model_info) Legion::Extensions::Llm::Routing::ModelOffering.new(**build_offering_kwargs( model_info: model_info, policy: policy, health: health )) end |
#readiness(live: false) ⇒ Object
214 215 216 217 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 214 def readiness(live: false) log.info("Checking MLX readiness (live=#{live})") super end |
#settings ⇒ Object
180 181 182 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 180 def settings Mlx.default_settings end |