Class: Legion::Extensions::Llm::Vertex::Actor::VertexCallable
- Inherits:
-
Object
- Object
- Legion::Extensions::Llm::Vertex::Actor::VertexCallable
- Defined in:
- lib/legion/extensions/llm/vertex/callable.rb
Overview
Callable wrapper for a Vertex AI provider instance. Delegates the
fleet dispatch operations to a per-instance Vertex::Provider (real
HTTP dispatch; provider/Faraday errors propagate so
normalize_dispatch_error classifies them) and implements the
disconnect and normalize_dispatch_error(error:) contracts
required by Inventory::CallableHandle and Routing::ProviderOutcome.
Instance Attribute Summary collapse
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Instance Method Summary collapse
-
#chat(messages:, model:, **rest) ⇒ Object
--- Fleet dispatch operations (Fleet::WorkerExecution contract) --.
- #count_tokens(messages:, model:, **rest) ⇒ Object
- #disconnect ⇒ Object
- #disconnected? ⇒ Boolean
- #embed(text:, model:, **rest) ⇒ Object
-
#initialize(instance_cfg:, logger:) ⇒ VertexCallable
constructor
A new instance of VertexCallable.
-
#normalize_dispatch_error(error:) ⇒ Object
--- Error normalization ------------------------------------------.
- #stream_chat(messages:, model:, **rest) ⇒ Object
Constructor Details
#initialize(instance_cfg:, logger:) ⇒ VertexCallable
Returns a new instance of VertexCallable.
21 22 23 24 25 26 |
# File 'lib/legion/extensions/llm/vertex/callable.rb', line 21 def initialize(instance_cfg:, logger:) @instance_cfg = instance_cfg @logger = logger @provider = Provider.new(instance_cfg) @disconnected = false end |
Instance Attribute Details
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
19 20 21 |
# File 'lib/legion/extensions/llm/vertex/callable.rb', line 19 def provider @provider end |
Instance Method Details
#chat(messages:, model:, **rest) ⇒ Object
--- Fleet dispatch operations (Fleet::WorkerExecution contract) --
40 41 42 |
# File 'lib/legion/extensions/llm/vertex/callable.rb', line 40 def chat(messages:, model:, **rest) provider.chat(messages: , model: model, **rest) end |
#count_tokens(messages:, model:, **rest) ⇒ Object
52 53 54 |
# File 'lib/legion/extensions/llm/vertex/callable.rb', line 52 def count_tokens(messages:, model:, **rest) provider.count_tokens(messages: , model: model, **rest) end |
#disconnect ⇒ Object
32 33 34 35 36 |
# File 'lib/legion/extensions/llm/vertex/callable.rb', line 32 def disconnect @disconnected = true @provider.disconnect @logger.debug { '[vertex][callable] disconnected' } end |
#disconnected? ⇒ Boolean
28 29 30 |
# File 'lib/legion/extensions/llm/vertex/callable.rb', line 28 def disconnected? @disconnected end |
#embed(text:, model:, **rest) ⇒ Object
48 49 50 |
# File 'lib/legion/extensions/llm/vertex/callable.rb', line 48 def (text:, model:, **rest) provider.(text: text, model: model, **rest) end |
#normalize_dispatch_error(error:) ⇒ Object
--- Error normalization ------------------------------------------
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/legion/extensions/llm/vertex/callable.rb', line 58 def normalize_dispatch_error(error:) reason = error..to_s[0, 512] kind = case error when Faraday::ConnectionFailed :connection_failure when Faraday::TimeoutError :timeout when Faraday::ClientError classify_client_error(error: error) when Faraday::ServerError classify_server_error(error: error) when Legion::Extensions::Llm::OverloadedError :overloaded else # ServiceUnavailableError and all other errors map to provider_error. # Never escalate to instance_unavailable from a typed error alone. :provider_error end Legion::Extensions::Llm::Routing::ProviderOutcome.new( kind: kind, reason: reason.empty? ? 'unknown dispatch error' : reason ) end |
#stream_chat(messages:, model:, **rest) ⇒ Object
44 45 46 |
# File 'lib/legion/extensions/llm/vertex/callable.rb', line 44 def stream_chat(messages:, model:, **rest, &) provider.stream_chat(messages: , model: model, **rest, &) end |