Class: Legion::Extensions::Llm::AzureFoundry::Helpers::Callable
- Inherits:
-
Object
- Object
- Legion::Extensions::Llm::AzureFoundry::Helpers::Callable
- 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
- #chat(messages, model:, **rest) ⇒ Object
- #count_tokens(messages:, model:, **rest) ⇒ Object
- #disconnect ⇒ Object
- #disconnected? ⇒ Boolean
- #embed(text:, model:, **rest) ⇒ Object
-
#initialize(instance_cfg:, logger:, provider: nil) ⇒ Callable
constructor
A new instance of Callable.
-
#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.
- #provider ⇒ Object
- #stream_chat(messages, model:, **rest) ⇒ Object
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(, model:, **rest) provider.() provider.chat(, 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.() # 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: , model: model, params: rest) end |
#disconnect ⇒ Object
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
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 (text:, model:, **rest) provider.(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 |
#provider ⇒ Object
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(, model:, **rest, &) provider.() provider.stream(, model: model, **rest, &) end |