Class: Legion::Extensions::Llm::Anthropic::Provider

Inherits:
Provider
  • Object
show all
Includes:
Logging::Helper
Defined in:
lib/legion/extensions/llm/anthropic/provider.rb

Overview

Anthropic Messages API provider implementation for the Legion::Extensions::Llm contract.

Defined Under Namespace

Modules: Capabilities

Constant Summary collapse

CONTEXT_WINDOWS =
{
  'claude-opus-4'   => 200_000,
  'claude-sonnet-4' => 200_000,
  'claude-haiku-4'  => 200_000,
  'claude-3-5'      => 200_000,
  'claude-3-opus'   => 200_000,
  'claude-3-sonnet' => 200_000,
  'claude-3-haiku'  => 200_000
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.capabilitiesObject



18
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 18

def capabilities = Capabilities

.configuration_optionsObject



16
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 16

def configuration_options = %i[anthropic_api_key anthropic_api_base anthropic_version]

.configuration_requirementsObject



17
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 17

def configuration_requirements = %i[anthropic_api_key]

.slugObject



15
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 15

def slug = 'anthropic'

Instance Method Details

#api_baseObject



36
37
38
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 36

def api_base
  config.anthropic_api_base || settings[:endpoint] || 'https://api.anthropic.com'
end

#completion_urlObject



47
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 47

def completion_url = '/v1/messages'

#embed(**_provider_options) ⇒ Object

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 55

def embed(**_provider_options)
  raise NotImplementedError, 'Anthropic does not expose embeddings through this provider'
end

#headersObject



40
41
42
43
44
45
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 40

def headers
  identity_headers.merge({
    'x-api-key'         => config.anthropic_api_key,
    'anthropic-version' => config.anthropic_version || settings.dig(:instances, :default, :api_version)
  }.compact)
end

#models_urlObject



49
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 49

def models_url = '/v1/models'

#settingsObject



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

def settings
  Anthropic.default_settings
end

#stream_urlObject



48
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 48

def stream_url = completion_url

#translatorObject



51
52
53
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 51

def translator
  @translator ||= Translator.new(config)
end