Module: Legion::LLM::Inventory
- Extended by:
- Legion::Logging::Helper
- Defined in:
- lib/legion/llm/inventory.rb
Constant Summary collapse
- DEFAULT_PROVIDER_TIERS =
{ ollama: :local, vllm: :fleet, mlx: :local, bedrock: :cloud, azure: :cloud, gemini: :cloud, anthropic: :frontier, openai: :frontier }.freeze
- DEFAULT_PROVIDER_TRANSPORTS =
{ ollama: :http, vllm: :http, mlx: :http, bedrock: :sdk, azure: :http, gemini: :http, anthropic: :http, openai: :http }.freeze
- DEFAULT_CAPABILITIES =
{ embed: %i[embed], inference: %i[chat completion tools json_schema], chat: %i[chat completion tools json_schema] }.freeze
- CAPABILITY_ALIASES =
{ function_calling: :tools, functions: :tools, tool: :tools, tool_use: :tools, stream: :streaming, stream_chat: :streaming }.freeze
Class Method Summary collapse
- .invalidate_offerings_cache! ⇒ Object
- .offerings(filters = {}) ⇒ Object
- .providers ⇒ Object
-
.routing_candidates(operation: :generation, **filters) ⇒ Object
Bounded routing-candidate set: ONE representative offering per enabled provider-instance for the given operation, drawn from the SAME merged catalog the API serves (settings + native adapter static catalogs + discovery).
Class Method Details
.invalidate_offerings_cache! ⇒ Object
48 49 50 51 |
# File 'lib/legion/llm/inventory.rb', line 48 def invalidate_offerings_cache! log.debug '[llm][inventory] action=invalidate_offerings_cache' @offerings_cache = nil end |
.offerings(filters = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/legion/llm/inventory.rb', line 53 def offerings(filters = {}) log.debug "[llm][inventory] action=offerings.enter filters=#{filters.keys}" normalized_filters = normalize_filter_hash(filters) provider_scope = normalized_filters[:provider]&.to_sym list = [] providers_config.each do |provider_family, config| next unless enabled_config?(config) next if provider_scope && provider_family.to_sym != provider_scope list.concat(provider_offerings(provider_family.to_sym, config)) end native = native_provider_offerings(provider: provider_scope) native_providers = native.map { |o| o[:provider_family]&.to_sym }.uniq list.concat(native) list.concat(discovery_offerings(provider: provider_scope, exclude_providers: native_providers)) list = dedupe_offerings(list) result = filter_offerings(list, normalized_filters) log.debug "[llm][inventory] action=offerings.complete total=#{result.size}" result rescue NameError, ArgumentError, TypeError => e handle_exception(e, level: :error, handled: false, operation: 'llm.inventory.offerings') raise rescue StandardError => e handle_exception(e, level: :warn, handled: true, operation: 'llm.inventory.offerings') [] end |
.providers ⇒ Object
81 82 83 |
# File 'lib/legion/llm/inventory.rb', line 81 def providers offerings.group_by { |offering| offering[:provider_family] } end |
.routing_candidates(operation: :generation, **filters) ⇒ Object
Bounded routing-candidate set: ONE representative offering per enabled provider-instance for the given operation, drawn from the SAME merged catalog the API serves (settings + native adapter static catalogs + discovery). This is the set the Router scores — it never enumerates a provider’s full catalog (e.g. OpenAI’s 100+ models). The representative is the provider’s declared default_model when that model is offered, else the settings-default offering, else the first offering.
92 93 94 95 96 97 98 |
# File 'lib/legion/llm/inventory.rb', line 92 def routing_candidates(operation: :generation, **filters) type = normalize_type(operation) catalog = offerings(filters.merge(type: type)) catalog .group_by { |offering| [offering[:provider_family].to_s, offering_instance_key(offering)] } .filter_map { |(provider_family, instance_key), group| representative_offering(provider_family, instance_key, group) } end |