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 ||= RegistryPublisher.new
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



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

def api_base
  config.mlx_api_base || 'http://localhost:8000'
end

#headersObject



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

def headers
  token = config.mlx_api_key
  return {} if token.nil? || token.to_s.empty?

  { 'Authorization' => "Bearer #{token}" }
end

#healthObject



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

def health
  connection.get(health_url).body
end

#health_urlObject



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

def health_url = '/health'

#list_modelsObject



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

def list_models
  super.tap do |models|
    self.class.registry_publisher.publish_models_async(models, readiness: readiness(live: false))
  end
end

#readiness(live: false) ⇒ Object



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

def readiness(live: false)
  super.tap do ||
    self.class.registry_publisher.publish_readiness_async() if live
  end
end