Module: Legion::LLM::Call::Providers
- Extended by:
- Legion::Logging::Helper
- Defined in:
- lib/legion/llm/call/providers.rb
Class Method Summary collapse
- .inject_anthropic_cache_control!(opts, provider) ⇒ Object
- .log_available ⇒ Object
-
.rediscover_all_providers ⇒ Object
– private helpers ————————————————–.
- .resolve_provider_module(family) ⇒ Object
- .setup ⇒ Object
Class Method Details
.inject_anthropic_cache_control!(opts, provider) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/legion/llm/call/providers.rb', line 23 def inject_anthropic_cache_control!(opts, provider) resolved_provider = (provider || Legion::LLM::Settings.value(:default_provider))&.to_sym return unless resolved_provider == :anthropic caching_settings = Legion::LLM::Settings.value(:prompt_caching, default: {}) || {} return unless Legion::LLM::Settings.config_value(caching_settings, :enabled, true) != false min_tokens = Legion::LLM::Settings.config_value(caching_settings, :min_tokens) || 1024 instructions = opts[:instructions] return unless instructions.is_a?(String) && instructions.length > min_tokens log.debug "[llm][providers] inject_anthropic_cache_control provider=#{resolved_provider} length=#{instructions.length}" opts[:instructions] = { content: instructions, cache_control: { type: 'ephemeral' } } end |
.log_available ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/legion/llm/call/providers.rb', line 61 def log_available instances = Call::Registry.all_instances if instances.any? summary = instances.map { |i| "#{i[:provider]}/#{i[:instance]}" }.join(', ') log.info "[llm][providers] available instances=#{summary}" else log.error '[llm][providers] no providers available — no instances registered' end end |
.rediscover_all_providers ⇒ Object
– private helpers ————————————————–
43 44 45 46 47 48 49 50 |
# File 'lib/legion/llm/call/providers.rb', line 43 def rediscover_all_providers Call::Registry.all_provider_families.each do |family| mod = resolve_provider_module(family) mod.rediscover! if mod.respond_to?(:rediscover!) end rescue StandardError => e handle_exception(e, level: :warn, operation: 'llm.providers.rediscover_all') end |
.resolve_provider_module(family) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/legion/llm/call/providers.rb', line 52 def resolve_provider_module(family) return nil unless defined?(Legion::Extensions::Llm) camel = family.to_s.split('_').map(&:capitalize).join Legion::Extensions::Llm.const_get(camel, false) rescue NameError nil end |
.setup ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/legion/llm/call/providers.rb', line 13 def setup log.debug '[llm][providers] setup.enter' rediscover_all_providers log_available log.debug '[llm][providers] setup.exit' rescue StandardError => e handle_exception(e, level: :error, operation: 'llm.providers.setup') raise end |