Class: Legion::Extensions::Llm::Ollama::Actor::OllamaCallable
- Inherits:
-
Object
- Object
- Legion::Extensions::Llm::Ollama::Actor::OllamaCallable
- Defined in:
- lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb
Overview
Callable wrapper for an Ollama provider instance. Implements the fleet dispatch ops (chat/stream_chat/embed/count_tokens) by delegating to a per-instance Ollama::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) ⇒ OllamaCallable
constructor
A new instance of OllamaCallable.
- #normalize_dispatch_error(error:) ⇒ Object
- #stream_chat(messages:, model:, **rest) ⇒ Object
Constructor Details
#initialize(instance_cfg:, logger:, provider: nil) ⇒ OllamaCallable
Returns a new instance of OllamaCallable.
991 992 993 994 995 996 |
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 991 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). Ollama's render path is string-tolerant (model.respond_to?(:id) ? model.id : model) for chat and embed, embed places the model verbatim in the Embedding response object, and count_tokens ignores it — so the model passes through UNWRAPPED on every op. Wrapping a raw string in Model::Info here would serialize a Data object into the wire payload or the response object (D15 per-op rule); Model::Info instances pass through unchanged as well.
1015 1016 1017 |
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 1015 def chat(messages:, model:, **rest) provider.chat(messages: , model: model, **rest) end |
#count_tokens(messages:, model:, **rest) ⇒ Object
1027 1028 1029 |
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 1027 def count_tokens(messages:, model:, **rest) provider.count_tokens(messages: , model: model, **rest) end |
#disconnect ⇒ Object
1000 1001 1002 1003 1004 |
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 1000 def disconnect @disconnected = true @provider&.disconnect @logger.debug { '[ollama][callable] disconnected' } end |
#disconnected? ⇒ Boolean
998 |
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 998 def disconnected? = @disconnected |
#embed(text:, model:, **rest) ⇒ Object
1023 1024 1025 |
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 1023 def (text:, model:, **rest) provider.(text: text, model: model, **rest) end |
#normalize_dispatch_error(error:) ⇒ Object
1031 1032 1033 1034 1035 1036 |
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 1031 def normalize_dispatch_error(error:) Legion::Extensions::Llm::Routing::ProviderOutcome.new( kind: classify_dispatch_error(error: error), reason: dispatch_reason(error) ) end |
#stream_chat(messages:, model:, **rest) ⇒ Object
1019 1020 1021 |
# File 'lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb', line 1019 def stream_chat(messages:, model:, **rest, &) provider.stream_chat(messages: , model: model, **rest, &) end |