Class: Legion::Extensions::Llm::Gemini::Helpers::Callable
- Inherits:
-
Object
- Object
- Legion::Extensions::Llm::Gemini::Helpers::Callable
- Includes:
- DispatchErrorClassification
- Defined in:
- lib/legion/extensions/llm/gemini/helpers/callable.rb
Overview
Callable wrapper for a Gemini provider instance. Implements the fleet dispatch ops (chat/stream_chat/embed/count_tokens) by delegating to a per-instance Gemini::Provider, plus the disconnect and normalize_dispatch_error contracts required by Inventory::CallableHandle and Routing::ProviderOutcome. Dispatch errors propagate untouched so normalize_dispatch_error can classify them.
Constant Summary collapse
- COMPLETION_NAMED_KEYS =
Named completion kwargs the base Provider funnel accepts directly (08 F3); everything else in the fleet's **rest is folded wire params that become a Canonical::Params at the boundary (05 O4 — temperature is a params member, never a kwarg).
%i[tools schema thinking tool_prefs headers].freeze
- EMBED_NAMED_KEYS =
%i[dimensions headers].freeze
Instance Method Summary collapse
-
#chat(messages, model:, **rest) ⇒ Object
Fleet and SelectionDispatch pass model as a RAW STRING (the offering's model id).
- #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
- #stream_chat(messages, model:, **rest) ⇒ Object
Constructor Details
#initialize(instance_cfg:, logger:, provider: nil) ⇒ Callable
Returns a new instance of Callable.
110 111 112 113 114 115 |
# File 'lib/legion/extensions/llm/gemini/helpers/callable.rb', line 110 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
Fleet and SelectionDispatch pass model as a RAW STRING (the offering's model id). It passes through untranslated to the provider funnel — the base model_identity and the Gemini renderer both accept the bare string (0.8.0 contract). messages is positional — the 0.8.0 funnel and fleet WorkerExecution both hand the canonical ArrayCanonical::Message positionally.
138 139 140 141 142 143 144 145 |
# File 'lib/legion/extensions/llm/gemini/helpers/callable.rb', line 138 def chat(, model:, **rest) # Canonical boundary (N x N law): pipeline dispatch delivers # Canonical::Message objects only. Hash/legacy shapes are the # bypass class — reject loudly, never coerce. provider.() named, params = split_fleet_kwargs(rest, COMPLETION_NAMED_KEYS) provider.chat(, model: model, params: canonical_params(params), **named) end |
#count_tokens(messages:, model:, **rest) ⇒ Object
158 159 160 161 162 |
# File 'lib/legion/extensions/llm/gemini/helpers/callable.rb', line 158 def count_tokens(messages:, model:, **rest) provider.() _named, params = split_fleet_kwargs(rest, []) provider.count_tokens(messages: , model: model, params: params) end |
#disconnect ⇒ Object
119 120 121 122 123 |
# File 'lib/legion/extensions/llm/gemini/helpers/callable.rb', line 119 def disconnect @disconnected = true @provider&.disconnect @logger.debug { '[gemini][callable] disconnected' } end |
#disconnected? ⇒ Boolean
117 |
# File 'lib/legion/extensions/llm/gemini/helpers/callable.rb', line 117 def disconnected? = @disconnected |
#embed(text:, model:, **rest) ⇒ Object
153 154 155 156 |
# File 'lib/legion/extensions/llm/gemini/helpers/callable.rb', line 153 def (text:, model:, **rest) named, params = split_fleet_kwargs(rest, EMBED_NAMED_KEYS) provider.(text: text, model: model, params: params, **named) end |
#normalize_dispatch_error(error:) ⇒ Object
164 165 166 167 168 169 |
# File 'lib/legion/extensions/llm/gemini/helpers/callable.rb', line 164 def normalize_dispatch_error(error:) reason = error..to_s[0, 512] Legion::Extensions::Llm::Routing::ProviderOutcome.new( kind: classify_dispatch_error(error: error), reason: reason.empty? ? 'unknown dispatch error' : reason ) end |
#stream_chat(messages, model:, **rest) ⇒ Object
147 148 149 150 151 |
# File 'lib/legion/extensions/llm/gemini/helpers/callable.rb', line 147 def stream_chat(, model:, **rest, &) provider.() named, params = split_fleet_kwargs(rest, COMPLETION_NAMED_KEYS) provider.stream_chat(, model: model, params: canonical_params(params), **named, &) end |