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



24
25
26
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 24

def registry_publisher
  @registry_publisher ||= Legion::Extensions::Llm::RegistryPublisher.new(provider_family: :mlx)
end

Class Method Details

.capabilitiesObject



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

def capabilities = Capabilities

.configuration_optionsObject



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

def configuration_options = %i[mlx_api_base mlx_api_key]

.configuration_requirementsObject



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

def configuration_requirements = []

.default_tierObject



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

def default_tier = :local

.default_transportObject



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

def default_transport = :http

.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



57
58
59
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 57

def api_base
  normalize_url(config.mlx_api_base || settings[:endpoint] || 'http://localhost:8000')
end

#headersObject



61
62
63
64
65
66
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 61

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



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

def health(live: false)
  log.info("Checking MLX health live=#{live} at #{api_base}#{health_url}")
  connection.get(health_url).body
end

#health_urlObject



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

def health_url = '/health'

#list_modelsObject



82
83
84
85
86
87
88
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 82

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



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

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



53
54
55
# File 'lib/legion/extensions/llm/mlx/provider.rb', line 53

def settings
  Mlx.default_settings
end