Class: Legion::Extensions::Llm::Anthropic::Actor::DiscoveryRefresh
- Inherits:
-
Actors::Every
- Object
- Actors::Every
- Legion::Extensions::Llm::Anthropic::Actor::DiscoveryRefresh
- Includes:
- Inventory::ScopedRefresher, Logging::Helper
- Defined in:
- lib/legion/extensions/llm/anthropic/actors/discovery_refresh.rb
Constant Summary collapse
- EMBED_TYPES =
%i[embed embedding].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #check_subtask? ⇒ Boolean
- #compute_lanes_for_scope ⇒ Object
- #credential_hash ⇒ Object
- #generate_task? ⇒ Boolean
- #manual ⇒ Object
- #run_now? ⇒ Boolean
- #runner_class ⇒ Object
- #runner_function ⇒ Object
- #scope_key ⇒ Object
- #time ⇒ Object
- #use_runner? ⇒ Boolean
Class Method Details
.every_seconds ⇒ Object
30 |
# File 'lib/legion/extensions/llm/anthropic/actors/discovery_refresh.rb', line 30 def self.every_seconds = 3600 |
Instance Method Details
#check_subtask? ⇒ Boolean
36 |
# File 'lib/legion/extensions/llm/anthropic/actors/discovery_refresh.rb', line 36 def check_subtask? = false |
#compute_lanes_for_scope ⇒ Object
49 50 51 52 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/legion/extensions/llm/anthropic/actors/discovery_refresh.rb', line 49 def compute_lanes_for_scope return [] unless defined?(Legion::LLM::Call::Registry) instances = Legion::LLM::Call::Registry.all_instances.select do |e| (e[:provider] || '').to_sym == :anthropic end lanes = [] instances.each do |instance| adapter = instance[:adapter] source = if adapter.respond_to?(:discover_offerings) then adapter.discover_offerings(live: true) elsif adapter.respond_to?(:offerings) then adapter.offerings(live: false) else next end Array(source).filter_map do |raw| offering = offering_to_hash(raw) next unless offering instance_id = instance[:instance] || instance[:instance_id] || instance[:id] || 'default' model = offering[:model] || offering[:id] next unless model offering_type = if EMBED_TYPES.include?((offering[:type] || '').to_sym) :embedding else :inference end tier = offering[:tier]&.to_sym || :frontier capabilities = if defined?(Legion::Extensions::Llm::Inventory::Capabilities) Legion::Extensions::Llm::Inventory::Capabilities.normalize(offering[:capabilities]) else Array(offering[:capabilities]) end lane_id = Legion::Extensions::Llm::Inventory::ScopedRefresher.compose_id( tier: tier, provider_family: :anthropic, instance_id: instance_id, type: offering_type, model: model ) lane = { id: lane_id, tier: tier, provider_family: :anthropic, instance_id: instance_id, model: model, canonical_model_alias: offering[:canonical_model_alias], type: offering_type, capabilities: capabilities, limits: offering[:limits] || {}, enabled: offering.fetch(:enabled, true), cost: offering[:cost] || {} }.compact lanes << lane # G29: also emit a fleet lane for each inference lane when fleet dispatch is configured if offering_type == :inference settings = Legion::Settings.dig(:extensions, :llm, :anthropic) || {} if settings[:fleet]&.dig(:dispatch, :enabled) fleet_id = Legion::Extensions::Llm::Inventory::ScopedRefresher.compose_id( tier: :fleet, provider_family: :anthropic, instance_id: instance_id, type: :inference, model: model ) lanes << lane.merge(id: fleet_id, tier: :fleet) end end end end lanes rescue StandardError => e handle_exception(e, level: :warn, handled: true, operation: 'anthropic.actor.discovery_refresh.compute_lanes') [] end |
#credential_hash ⇒ Object
135 136 137 138 |
# File 'lib/legion/extensions/llm/anthropic/actors/discovery_refresh.rb', line 135 def credential_hash settings = Legion::Settings.dig(:extensions, :llm, :anthropic) || {} Digest::SHA256.hexdigest(settings[:api_key].to_s + settings[:instances].to_s)[0, 16] end |
#generate_task? ⇒ Boolean
37 |
# File 'lib/legion/extensions/llm/anthropic/actors/discovery_refresh.rb', line 37 def generate_task? = false |
#manual ⇒ Object
140 141 142 143 144 |
# File 'lib/legion/extensions/llm/anthropic/actors/discovery_refresh.rb', line 140 def manual tick if respond_to?(:tick) rescue StandardError => e handle_exception(e, level: :warn, handled: true, operation: 'anthropic.actor.discovery_refresh') end |
#run_now? ⇒ Boolean
34 |
# File 'lib/legion/extensions/llm/anthropic/actors/discovery_refresh.rb', line 34 def run_now? = true |
#runner_class ⇒ Object
32 |
# File 'lib/legion/extensions/llm/anthropic/actors/discovery_refresh.rb', line 32 def runner_class = self.class |
#runner_function ⇒ Object
33 |
# File 'lib/legion/extensions/llm/anthropic/actors/discovery_refresh.rb', line 33 def runner_function = 'manual' |
#scope_key ⇒ Object
45 46 47 |
# File 'lib/legion/extensions/llm/anthropic/actors/discovery_refresh.rb', line 45 def scope_key { provider: :anthropic } end |
#time ⇒ Object
39 40 41 42 43 |
# File 'lib/legion/extensions/llm/anthropic/actors/discovery_refresh.rb', line 39 def time return self.class.every_seconds unless defined?(Legion::Settings) Legion::Settings.dig(:extensions, :llm, :anthropic, :discovery_interval) || self.class.every_seconds end |
#use_runner? ⇒ Boolean
35 |
# File 'lib/legion/extensions/llm/anthropic/actors/discovery_refresh.rb', line 35 def use_runner? = false |