Class: Legion::Extensions::Llm::Mlx::Provider
- Inherits:
-
Provider
- Object
- Provider
- Legion::Extensions::Llm::Mlx::Provider
- Includes:
- Provider::OpenAICompatible
- Defined in:
- lib/legion/extensions/llm/mlx/provider.rb
Overview
MLX provider implementation for local OpenAI-compatible servers.
Defined Under Namespace
Modules: Capabilities
Class Attribute Summary collapse
Class Method Summary collapse
- .capabilities ⇒ Object
- .configuration_options ⇒ Object
- .configuration_requirements ⇒ Object
- .local? ⇒ Boolean
- .slug ⇒ Object
Instance Method Summary collapse
- #api_base ⇒ Object
- #headers ⇒ Object
- #health ⇒ Object
- #health_url ⇒ Object
- #list_models ⇒ Object
- #readiness(live: false) ⇒ Object
- #settings ⇒ Object
Class Attribute Details
.registry_publisher ⇒ Object
22 23 24 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 22 def registry_publisher @registry_publisher ||= Legion::Extensions::Llm::RegistryPublisher.new(provider_family: :mlx) end |
Class Method Details
.capabilities ⇒ Object
20 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 20 def capabilities = Capabilities |
.configuration_options ⇒ Object
18 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 18 def = %i[mlx_api_base mlx_api_key] |
.configuration_requirements ⇒ Object
19 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 19 def configuration_requirements = [] |
.local? ⇒ Boolean
17 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 17 def local? = true |
.slug ⇒ Object
16 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 16 def slug = 'mlx' |
Instance Method Details
#api_base ⇒ Object
55 56 57 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 55 def api_base normalize_url(config.mlx_api_base || 'localhost:8000') end |
#headers ⇒ Object
59 60 61 62 63 64 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 59 def headers token = config.mlx_api_key return {} if token.nil? || token.to_s.empty? { 'Authorization' => "Bearer #{token}" } end |
#health ⇒ Object
68 69 70 71 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 68 def health log.info("Checking MLX health at #{api_base}#{health_url}") connection.get(health_url).body end |
#health_url ⇒ Object
66 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 66 def health_url = '/health' |
#list_models ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 80 def list_models log.info('Listing available MLX models') super.tap do |models| log.info("Discovered #{Array(models).size} MLX models") self.class.registry_publisher.publish_models_async(models, readiness: readiness(live: false)) end end |
#readiness(live: false) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 73 def readiness(live: false) log.info("Checking MLX readiness (live=#{live})") super.tap do || self.class.registry_publisher.publish_readiness_async() if live end end |
#settings ⇒ Object
51 52 53 |
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 51 def settings Mlx.default_settings end |