Module: Legion::LLM::Call::Dispatch
- Extended by:
- Dispatch, Legion::Logging::Helper
- Included in:
- Dispatch
- Defined in:
- lib/legion/llm/call/dispatch.rb
Constant Summary collapse
- CAPABILITY_METHODS =
Mapping of supported capability names to extension method names.
{ chat: :chat, stream: :stream, embed: :embed, image: :image, count_tokens: :count_tokens }.freeze
Instance Method Summary collapse
-
#available?(provider) ⇒ Boolean
Returns true when the provider is registered in Registry.
-
#call(provider:, capability:, instance: nil, model: nil) ⇒ Hash
Generic dispatch entry point.
-
#dispatch_chat(provider:, model:, messages:) ⇒ Object
deprecated
Deprecated.
Use #call with ‘capability: :chat` instead.
-
#dispatch_count_tokens(provider:, model:, messages:) ⇒ Object
deprecated
Deprecated.
Use #call with ‘capability: :count_tokens` instead.
-
#dispatch_embed(provider:, model:, text:) ⇒ Object
deprecated
Deprecated.
Use #call with ‘capability: :embed` instead.
-
#dispatch_stream(provider:, model:, messages:) ⇒ Object
deprecated
Deprecated.
Use #call with ‘capability: :stream` instead.
Instance Method Details
#available?(provider) ⇒ Boolean
Returns true when the provider is registered in Registry.
243 244 245 |
# File 'lib/legion/llm/call/dispatch.rb', line 243 def available?(provider) Registry.registered?(provider) end |
#call(provider:, capability:, instance: nil, model: nil) ⇒ Hash
Generic dispatch entry point. Routes to the appropriate extension method based on the capability name.
186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/legion/llm/call/dispatch.rb', line 186 def call(provider:, capability:, instance: nil, model: nil, **, &) cap_sym = capability.to_sym method_name = CAPABILITY_METHODS[cap_sym] raise Legion::LLM::ProviderError, "unsupported capability: #{capability}" unless method_name ext = fetch_extension!(provider, instance: instance) log.info("[llm][dispatch] capability=#{cap_sym} provider=#{provider} " \ "instance=#{instance || 'default'} model=#{model}") raw = ext.public_send(method_name, model: model, **, &) normalize_response(raw) end |
#dispatch_chat(provider:, model:, messages:) ⇒ Object
Deprecated.
Use #call with ‘capability: :chat` instead.
204 205 206 207 208 209 210 |
# File 'lib/legion/llm/call/dispatch.rb', line 204 def dispatch_chat(provider:, model:, messages:, **) unless @chat_deprecation_warned log.warn('[llm][dispatch] DEPRECATED: dispatch_chat — use Dispatch.call(capability: :chat)') @chat_deprecation_warned = true end call(provider: provider, capability: :chat, model: model, messages: , **) end |
#dispatch_count_tokens(provider:, model:, messages:) ⇒ Object
Deprecated.
Use #call with ‘capability: :count_tokens` instead.
231 232 233 234 235 236 237 |
# File 'lib/legion/llm/call/dispatch.rb', line 231 def dispatch_count_tokens(provider:, model:, messages:, **) unless @count_tokens_deprecation_warned log.warn('[llm][dispatch] DEPRECATED: dispatch_count_tokens — use Dispatch.call(capability: :count_tokens)') @count_tokens_deprecation_warned = true end call(provider: provider, capability: :count_tokens, model: model, messages: , **) end |
#dispatch_embed(provider:, model:, text:) ⇒ Object
Deprecated.
Use #call with ‘capability: :embed` instead.
213 214 215 216 217 218 219 |
# File 'lib/legion/llm/call/dispatch.rb', line 213 def (provider:, model:, text:, **) unless @embed_deprecation_warned log.warn('[llm][dispatch] DEPRECATED: dispatch_embed — use Dispatch.call(capability: :embed)') @embed_deprecation_warned = true end call(provider: provider, capability: :embed, model: model, text: text, **) end |
#dispatch_stream(provider:, model:, messages:) ⇒ Object
Deprecated.
Use #call with ‘capability: :stream` instead.
222 223 224 225 226 227 228 |
# File 'lib/legion/llm/call/dispatch.rb', line 222 def dispatch_stream(provider:, model:, messages:, **, &) unless @stream_deprecation_warned log.warn('[llm][dispatch] DEPRECATED: dispatch_stream — use Dispatch.call(capability: :stream)') @stream_deprecation_warned = true end call(provider: provider, capability: :stream, model: model, messages: , **, &) end |