Module: Legion::Extensions::Llm::Anthropic
- Extended by:
- AutoRegistration, Logging::Helper
- Defined in:
- lib/legion/extensions/llm/anthropic.rb,
lib/legion/extensions/llm/anthropic/version.rb,
lib/legion/extensions/llm/anthropic/provider.rb,
lib/legion/extensions/llm/anthropic/translator.rb,
lib/legion/extensions/llm/anthropic/actors/discovery.rb,
lib/legion/extensions/llm/anthropic/helpers/callable.rb,
lib/legion/extensions/llm/anthropic/runners/discovery.rb,
lib/legion/extensions/llm/anthropic/actors/fleet_worker.rb,
lib/legion/extensions/llm/anthropic/runners/fleet_worker.rb,
lib/legion/extensions/llm/anthropic/transport/exchanges/llm_registry.rb
Overview
Anthropic provider extension namespace.
Defined Under Namespace
Modules: Actor, Helpers, Runners, Transport Classes: Provider, Translator
Constant Summary collapse
- PROVIDER_FAMILY =
:anthropic- VERSION =
'0.3.7'
Class Method Summary collapse
- .default_settings ⇒ Object
- .discover_instances ⇒ Object
- .normalize_instance_config(config) ⇒ Object
- .provider_aliases ⇒ Object
- .provider_class ⇒ Object
- .sanitize_instance_config(config) ⇒ Object
- .settings_instances(config) ⇒ Object
Class Method Details
.default_settings ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/legion/extensions/llm/anthropic.rb', line 21 def self.default_settings ::Legion::Extensions::Llm.provider_settings( family: PROVIDER_FAMILY, instance: { endpoint: 'https://api.anthropic.com', api_version: '2023-10-16', default_max_tokens: 4096, discovery_interval: 3600, tier: :frontier, transport: :http, credentials: { api_key: 'env://ANTHROPIC_API_KEY' }, usage: { inference: true, embedding: false, image: false }, limits: { concurrency: 4 }, prompt_caching: {}, fleet: { enabled: false, respond_to_requests: false, capabilities: %i[chat stream_chat] } } ) end |
.discover_instances ⇒ Object
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 |
# File 'lib/legion/extensions/llm/anthropic.rb', line 52 def self.discover_instances candidates = {} env_key = CredentialSources.env('ANTHROPIC_API_KEY') if env_key candidates[:env] = { api_key: env_key, anthropic_api_key: env_key, tier: :frontier, source: CredentialSources.source_tag(:env, 'ANTHROPIC_API_KEY'), credential_fingerprint: CredentialSources.credential_fingerprint(env_key) } end claude_key = CredentialSources.claude_config_value(:anthropicApiKey) if claude_key candidates[:claude] = { api_key: claude_key, anthropic_api_key: claude_key, tier: :frontier, source: CredentialSources.source_tag(:file, '~/.claude/settings.json', 'anthropicApiKey'), credential_fingerprint: CredentialSources.credential_fingerprint(claude_key) } end settings_config = CredentialSources.setting(:extensions, :llm, :anthropic) if settings_config.is_a?(Hash) settings_key = settings_config[:api_key] || settings_config['api_key'] if settings_key candidates[:settings] = normalize_instance_config(settings_config).merge( api_key: settings_key, anthropic_api_key: settings_key, tier: :frontier, source: CredentialSources.source_tag(:settings, 'extensions.llm.anthropic'), credential_fingerprint: CredentialSources.credential_fingerprint(settings_key) ) end settings_instances(settings_config).each do |name, config| next unless config.is_a?(Hash) normalized = normalize_instance_config(config) next unless normalized[:anthropic_api_key] # enabled: false is an operator shutdown — the shared pipeline # claims whatever this catalog returns, so the filter lives here # (single source for both the dispatch and discovery paths). next if normalized[:enabled] == false normalized[:api_key] = normalized[:anthropic_api_key] normalized[:source] = CredentialSources.source_tag(:settings, "extensions.llm.anthropic.instances.#{name}") normalized[:credential_fingerprint] = CredentialSources.credential_fingerprint(normalized[:anthropic_api_key]) candidates[name.to_sym] = normalized.merge(tier: :frontier) end end if defined?(Legion::Identity::Broker) broker_cred = Legion::Identity::Broker.credential_for(:anthropic) if broker_cred candidates[:broker] = { api_key: broker_cred, anthropic_api_key: broker_cred, tier: :frontier, source: CredentialSources.source_tag(:broker, 'identity', 'anthropic'), credential_fingerprint: CredentialSources.credential_fingerprint(broker_cred) } end end CredentialSources.dedup_credentials(candidates).transform_values do |config| sanitized = sanitize_instance_config(config) sanitized[:capabilities] ||= %i[completion streaming vision tools].freeze sanitized end end |
.normalize_instance_config(config) ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/legion/extensions/llm/anthropic.rb', line 134 def self.normalize_instance_config(config) normalized = config.to_h.transform_keys { |key| key.respond_to?(:to_sym) ? key.to_sym : key } normalized[:anthropic_api_key] ||= normalized.delete(:api_key) normalized[:anthropic_api_base] ||= normalized.delete(:base_url) normalized[:anthropic_api_base] ||= normalized.delete(:api_base) normalized[:anthropic_api_base] ||= normalized.delete(:endpoint) normalized[:anthropic_version] ||= normalized.delete(:version) normalized.compact.except(:instances) end |
.provider_aliases ⇒ Object
48 49 50 |
# File 'lib/legion/extensions/llm/anthropic.rb', line 48 def self.provider_aliases [] end |
.provider_class ⇒ Object
44 45 46 |
# File 'lib/legion/extensions/llm/anthropic.rb', line 44 def self.provider_class Provider end |
.sanitize_instance_config(config) ⇒ Object
144 145 146 |
# File 'lib/legion/extensions/llm/anthropic.rb', line 144 def self.sanitize_instance_config(config) config.except(:api_key) end |
.settings_instances(config) ⇒ Object
129 130 131 132 |
# File 'lib/legion/extensions/llm/anthropic.rb', line 129 def self.settings_instances(config) instances = config[:instances] || config['instances'] instances.is_a?(Hash) ? instances : {} end |