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

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

Instance Method Summary collapse

Class Method Details

.capabilitiesObject



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

def capabilities = Capabilities

.configuration_optionsObject



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

def configuration_options = %i[mlx_api_base mlx_api_key]

.configuration_requirementsObject



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

def configuration_requirements = []

.default_tierObject



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

def default_tier = :local

.default_transportObject



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

def default_transport = :http

.local?Boolean

Returns:

  • (Boolean)


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

def local? = true

.slugObject



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

def slug = 'mlx'

Instance Method Details

#api_baseObject



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

#headersObject



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.message
  }
end

#health_urlObject



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

#settingsObject



78
79
80
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 78

def settings
  Mlx.default_settings
end