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, responses: :responses, 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.
247 248 249 |
# File 'lib/legion/llm/call/dispatch.rb', line 247 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.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/legion/llm/call/dispatch.rb', line 187 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) if ext.respond_to?(:supports?) && !ext.supports?(cap_sym) raise Legion::LLM::ProviderError, "unsupported capability #{capability} for provider #{provider}" end 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.
208 209 210 211 212 213 214 |
# File 'lib/legion/llm/call/dispatch.rb', line 208 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.
235 236 237 238 239 240 241 |
# File 'lib/legion/llm/call/dispatch.rb', line 235 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.
217 218 219 220 221 222 223 |
# File 'lib/legion/llm/call/dispatch.rb', line 217 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.
226 227 228 229 230 231 232 |
# File 'lib/legion/llm/call/dispatch.rb', line 226 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 |