Class: Legion::Extensions::Llm::Mlx::Provider
- Inherits:
-
Provider
- Object
- Provider
- Legion::Extensions::Llm::Mlx::Provider
- Includes:
- 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
- #readiness(live: false) ⇒ Object
- #settings ⇒ Object
Class Method Details
.capabilities ⇒ Object
75 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 75 def capabilities = Capabilities |
.configuration_options ⇒ Object
73 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 73 def = %i[mlx_api_base mlx_api_key] |
.configuration_requirements ⇒ Object
74 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 74 def configuration_requirements = [] |
.default_tier ⇒ Object
72 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 72 def default_tier = :local |
.default_transport ⇒ Object
71 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 71 def default_transport = :http |
.local? ⇒ Boolean
70 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 70 def local? = true |
.slug ⇒ Object
69 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 69 def slug = 'mlx' |
Instance Method Details
#api_base ⇒ Object
82 83 84 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 82 def api_base normalize_url(config.mlx_api_base || settings[:instances][:default][:endpoint]) end |
#headers ⇒ Object
86 87 88 89 90 91 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 86 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
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 95 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
93 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 93 def health_url = '/health' |
#readiness(live: false) ⇒ Object
112 113 114 115 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 112 def readiness(live: false) log.info("Checking MLX readiness (live=#{live})") super end |
#settings ⇒ Object
78 79 80 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 78 def settings Mlx.default_settings end |