Class: Legion::Extensions::Llm::Gemini::Actor::GeminiCallable
- Inherits:
-
Object
- Object
- Legion::Extensions::Llm::Gemini::Actor::GeminiCallable
- Defined in:
- lib/legion/extensions/llm/gemini/actors/discovery_refresh.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.
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) ⇒ GeminiCallable
constructor
A new instance of GeminiCallable.
- #normalize_dispatch_error(error:) ⇒ Object
- #stream_chat(messages:, model:, **rest) ⇒ Object
Constructor Details
#initialize(instance_cfg:, logger:, provider: nil) ⇒ GeminiCallable
Returns a new instance of GeminiCallable.
1024 1025 1026 1027 1028 1029 |
# File 'lib/legion/extensions/llm/gemini/actors/discovery_refresh.rb', line 1024 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). Gemini's render path calls model.id (MessageFormatter#render_payload), so a raw string must be wrapped before delegation; Model::Info instances pass through.
1043 1044 1045 |
# File 'lib/legion/extensions/llm/gemini/actors/discovery_refresh.rb', line 1043 def chat(messages:, model:, **rest) provider.chat(messages: , model: llm_model(model), **rest) end |
#count_tokens(messages:, model:, **rest) ⇒ Object
1055 1056 1057 |
# File 'lib/legion/extensions/llm/gemini/actors/discovery_refresh.rb', line 1055 def count_tokens(messages:, model:, **rest) provider.count_tokens(messages: , model: llm_model(model), **rest) end |
#disconnect ⇒ Object
1033 1034 1035 1036 1037 |
# File 'lib/legion/extensions/llm/gemini/actors/discovery_refresh.rb', line 1033 def disconnect @disconnected = true @provider&.disconnect @logger.debug { '[gemini][callable] disconnected' } end |
#disconnected? ⇒ Boolean
1031 |
# File 'lib/legion/extensions/llm/gemini/actors/discovery_refresh.rb', line 1031 def disconnected? = @disconnected |
#embed(text:, model:, **rest) ⇒ Object
1051 1052 1053 |
# File 'lib/legion/extensions/llm/gemini/actors/discovery_refresh.rb', line 1051 def (text:, model:, **rest) provider.(text: text, model: llm_model(model), **rest) end |
#normalize_dispatch_error(error:) ⇒ Object
1059 1060 1061 1062 1063 1064 |
# File 'lib/legion/extensions/llm/gemini/actors/discovery_refresh.rb', line 1059 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
1047 1048 1049 |
# File 'lib/legion/extensions/llm/gemini/actors/discovery_refresh.rb', line 1047 def stream_chat(messages:, model:, **rest, &) provider.stream_chat(messages: , model: llm_model(model), **rest, &) end |