Class: Legion::Extensions::Llm::AzureFoundry::Helpers::Callable

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/llm/azure_foundry/helpers/callable.rb

Overview

Callable wrapper for an Azure Foundry provider instance. Implements the fleet dispatch operations by delegating to the per-instance AzureFoundry::Provider (errors propagate so normalize_dispatch_error can classify them), plus the disconnect and normalize_dispatch_error(error:) contracts required by Inventory::CallableHandle and Routing::ProviderOutcome.

The callable is the second canonical entry form (08 F2, 12/O05): the shared lex-llm enforce_canonical_messages! helper runs at each message-operation entry. The fleet passes model: as the offering's model id (String) — it travels to the wire untouched (08 F3, B4: no model re-derivation, no Model::Info fabrication).

Instance Method Summary collapse

Constructor Details

#initialize(instance_cfg:, logger:, provider: nil) ⇒ Callable

Returns a new instance of Callable.



24
25
26
27
28
29
# File 'lib/legion/extensions/llm/azure_foundry/helpers/callable.rb', line 24

def initialize(instance_cfg:, logger:, provider: nil)
  @instance_cfg = instance_cfg
  @logger = logger
  @provider = provider
  @disconnected = false
end

Instance Method Details

#chat(messages, model:, **rest) ⇒ Object



45
46
47
48
# File 'lib/legion/extensions/llm/azure_foundry/helpers/callable.rb', line 45

def chat(messages, model:, **rest)
  provider.enforce_canonical_messages!(messages)
  provider.chat(messages, model: model, **rest)
end

#count_tokens(messages:, model:, **rest) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/legion/extensions/llm/azure_foundry/helpers/callable.rb', line 59

def count_tokens(messages:, model:, **rest)
  provider.enforce_canonical_messages!(messages)
  # The base heuristic ignores params (05 §2) — the fleet rest
  # folds into the params: slot rather than splatting into the
  # fixed base signature.
  provider.count_tokens(messages: messages, model: model, params: rest)
end

#disconnectObject



39
40
41
42
43
# File 'lib/legion/extensions/llm/azure_foundry/helpers/callable.rb', line 39

def disconnect
  @disconnected = true
  @provider&.disconnect
  @logger.debug { '[azure_foundry][callable] disconnected' }
end

#disconnected?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/legion/extensions/llm/azure_foundry/helpers/callable.rb', line 35

def disconnected?
  @disconnected
end

#embed(text:, model:, **rest) ⇒ Object



55
56
57
# File 'lib/legion/extensions/llm/azure_foundry/helpers/callable.rb', line 55

def embed(text:, model:, **rest)
  provider.embed(text: text, model: model, **rest)
end

#normalize_dispatch_error(error:) ⇒ Object

D17: production dispatch raises Legion::Extensions::Llm::*Error (ErrorMiddleware), not raw Faraday — the base Provider#normalize_dispatch_error classifies those. On top, Azure wire semantics supply two stronger signals: an explicit EndpointDeactivated body (the ONLY instance_unavailable signal) and a model-not-ready 503 body (request-local, not instance-down).



73
74
75
76
77
78
79
80
# File 'lib/legion/extensions/llm/azure_foundry/helpers/callable.rb', line 73

def normalize_dispatch_error(error:)
  outcome = base_provider_outcome(error: error)
  return outcome_with_kind(outcome, :instance_unavailable) if explicit_endpoint_deactivated?(error: error)
  return outcome_with_kind(outcome, :model_not_ready) if model_not_ready_outcome?(outcome, error: error)
  return outcome_with_kind(outcome, :model_missing) if model_missing_outcome?(outcome, error: error)

  outcome
end

#providerObject



31
32
33
# File 'lib/legion/extensions/llm/azure_foundry/helpers/callable.rb', line 31

def provider
  @provider ||= Legion::Extensions::Llm::AzureFoundry::Provider.new(@instance_cfg)
end

#stream_chat(messages, model:, **rest) ⇒ Object



50
51
52
53
# File 'lib/legion/extensions/llm/azure_foundry/helpers/callable.rb', line 50

def stream_chat(messages, model:, **rest, &)
  provider.enforce_canonical_messages!(messages)
  provider.stream(messages, model: model, **rest, &)
end