Module: Legion::Extensions::Llm::Anthropic

Extended by:
Core, AutoRegistration
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/registry_publisher.rb,
lib/legion/extensions/llm/anthropic/registry_event_builder.rb,
lib/legion/extensions/llm/anthropic/transport/exchanges/llm_registry.rb,
lib/legion/extensions/llm/anthropic/transport/messages/registry_event.rb

Overview

Anthropic provider extension namespace.

Defined Under Namespace

Modules: Transport Classes: Provider, RegistryEventBuilder, RegistryPublisher

Constant Summary collapse

PROVIDER_FAMILY =
:anthropic
VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.default_settingsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/legion/extensions/llm/anthropic.rb', line 19

def self.default_settings
  ::Legion::Extensions::Llm.provider_settings(
    family: PROVIDER_FAMILY,
    instance: {
      endpoint: 'https://api.anthropic.com',
      tier: :frontier,
      transport: :http,
      credentials: { api_key: 'env://ANTHROPIC_API_KEY' },
      usage: { inference: true, embedding: false },
      limits: { concurrency: 4 }
    }
  )
end

.discover_instancesObject

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity



37
38
39
40
41
42
43
44
45
46
47
48
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
# File 'lib/legion/extensions/llm/anthropic.rb', line 37

def self.discover_instances # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
  candidates = {}

  env_key = CredentialSources.env('ANTHROPIC_API_KEY')
  if env_key
    candidates[:env] = {
      api_key: env_key,
      anthropic_api_key: env_key,
      tier: :frontier
    }
  end

  claude_key = CredentialSources.claude_config_value(:anthropicApiKey)
  if claude_key
    candidates[:claude] = {
      api_key: claude_key,
      anthropic_api_key: claude_key,
      tier: :frontier
    }
  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] = settings_config.merge(
        anthropic_api_key: settings_key,
        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
      }
    end
  end

  CredentialSources.dedup_credentials(candidates)
end

.provider_classObject



33
34
35
# File 'lib/legion/extensions/llm/anthropic.rb', line 33

def self.provider_class
  Provider
end

.register_discovered_instancesObject



83
84
85
86
87
88
89
90
# File 'lib/legion/extensions/llm/anthropic.rb', line 83

def self.register_discovered_instances
  super
  return unless defined?(Legion::LLM::Call::Registry)

  Legion::LLM::Call::Registry.instances_for(:anthropic).each do |instance_id, adapter|
    Legion::LLM::Call::Registry.register(:claude, adapter, instance: instance_id)
  end
end