Module: Legion::Extensions::Llm::Mlx

Extended by:
AutoRegistration, Logging::Helper
Defined in:
lib/legion/extensions/llm/mlx.rb,
lib/legion/extensions/llm/mlx/version.rb,
lib/legion/extensions/llm/mlx/provider.rb,
lib/legion/extensions/llm/mlx/actors/discovery.rb,
lib/legion/extensions/llm/mlx/helpers/callable.rb,
lib/legion/extensions/llm/mlx/runners/discovery.rb,
lib/legion/extensions/llm/mlx/actors/fleet_worker.rb,
lib/legion/extensions/llm/mlx/runners/fleet_worker.rb

Overview

Mlx provider extension namespace.

Defined Under Namespace

Modules: Actor, Capabilities, HealthHelpers, Helpers, Runners Classes: Provider

Constant Summary collapse

PROVIDER_FAMILY =
:mlx
VERSION =
'0.5.4'

Class Method Summary collapse

Class Method Details

.configured_instancesObject

Only instances the operator actually configured are claimable. The synthetic instances.default section (provider_settings nests the extension's own instance defaults there at boot) is skipped with a once-per-boot warn while it is still the unmodified extension default — an unconfigured phantom must never be auto-registered, and a localhost endpoint is never a fallback identity.



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/legion/extensions/llm/mlx.rb', line 65

def self.configured_instances
  provider_cfg = Legion::Settings.dig(:extensions, :llm, :mlx) || {}
  instances = {}
  cfg_instances = provider_cfg[:instances]
  if cfg_instances.is_a?(Hash)
    cfg_instances.each do |name, config|
      normalized = normalize_instance_config(config)
      instances[name.to_sym] = normalized
    end
  end
  instances
end

.default_settingsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/legion/extensions/llm/mlx.rb', line 19

def self.default_settings
  ::Legion::Extensions::Llm.provider_settings(
    family: PROVIDER_FAMILY,
    instance: {
      endpoint: 'http://localhost:8000',
      tier: :local,
      transport: :http,
      credentials: { api_key: nil },
      usage: { inference: true, embedding: true, image: false },
      limits: { concurrency: 1 },
      fleet: {
        enabled: false,
        respond_to_requests: false,
        capabilities: %i[chat stream_chat embed]
      }
    }
  )
end

.discover_instancesObject

Single source of truth for MLX instance discovery. The SSOT discovery actor and the fleet responder both read this: only operator-configured instances. No port-scanning, no fabricated instances, no tier override.



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/legion/extensions/llm/mlx.rb', line 46

def self.discover_instances
  configured_instances.reject do |_, normalized|
    # enabled: false is a skip, not a claimable instance: the shared
    # Discovery::Pipeline reads this method as the single claimable
    # source and would otherwise claim + publish a disabled instance
    # as a live lane (an operator's enabled: false is user-space
    # intent). A credential-less instance (no api base to call) is
    # equally non-claimable — same skip as the vLLM sibling.
    normalized[:enabled] == false || normalized[:mlx_api_base].to_s.strip.empty?
  end
end

.normalized_synthetic_default_instanceObject



92
93
94
95
96
# File 'lib/legion/extensions/llm/mlx.rb', line 92

def self.normalized_synthetic_default_instance
  @normalized_synthetic_default_instance ||= normalize_instance_config(
    default_settings.dig(:instances, :default) || {}
  )
end

.provider_classObject



38
39
40
# File 'lib/legion/extensions/llm/mlx.rb', line 38

def self.provider_class
  Provider
end

.unconfigured_default?(name:, normalized:) ⇒ Boolean

The synthetic default is the extension's OWN registered instance defaults (endpoint http://localhost:8000 + fleet/limits blocks), deep-merged into instances.default by provider_settings. It is "configured" only when the operator changed something — a configured 'default' passes the provider layer and reaches the claim path (v2 parity: 'default' is a plain instance label). ONE predicate, TWO consumers: the actor's claim path (tick_refresh iterates configured_instances into claim_and_activate_instance) and the fleet responder (discover_instances → configured_instances) both reach it through this single filter point — no drift.

Returns:

  • (Boolean)


88
89
90
# File 'lib/legion/extensions/llm/mlx.rb', line 88

def self.unconfigured_default?(name:, normalized:)
  name.to_sym == :default && normalized == normalized_synthetic_default_instance
end