Class: Legion::Extensions::Llm::Mlx::Provider

Inherits:
Provider
  • Object
show all
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

Instance Method Summary collapse

Class Attribute Details

.registry_publisherObject



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

.capabilitiesObject



20
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 20

def capabilities = Capabilities

.configuration_optionsObject



18
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 18

def configuration_options = %i[mlx_api_base mlx_api_key]

.configuration_requirementsObject



19
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 19

def configuration_requirements = []

.local?Boolean

Returns:

  • (Boolean)


17
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 17

def local? = true

.slugObject



16
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 16

def slug = 'mlx'

Instance Method Details

#api_baseObject



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

#headersObject



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

#healthObject



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_urlObject



66
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 66

def health_url = '/health'

#list_modelsObject



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

#settingsObject



51
52
53
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 51

def settings
  Mlx.default_settings
end