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, 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.
161 162 163 |
# File 'lib/legion/llm/call/dispatch.rb', line 161 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.
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/legion/llm/call/dispatch.rb', line 104 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.
122 123 124 125 126 127 128 |
# File 'lib/legion/llm/call/dispatch.rb', line 122 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.
149 150 151 152 153 154 155 |
# File 'lib/legion/llm/call/dispatch.rb', line 149 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.
131 132 133 134 135 136 137 |
# File 'lib/legion/llm/call/dispatch.rb', line 131 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.
140 141 142 143 144 145 146 |
# File 'lib/legion/llm/call/dispatch.rb', line 140 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 |