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

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.registry_publisherObject



22
23
24
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 22

def registry_publisher
  @registry_publisher ||= RegistryPublisher.new
end

Class Method Details

.capabilitiesObject



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

def capabilities = Capabilities

.configuration_optionsObject



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

def configuration_options = %i[anthropic_api_key anthropic_api_base anthropic_version]

.configuration_requirementsObject



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

def configuration_requirements = %i[anthropic_api_key]

.slugObject



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

def slug = 'anthropic'

Instance Method Details

#api_baseObject



38
39
40
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 38

def api_base
  config.anthropic_api_base || 'https://api.anthropic.com'
end

#completion_urlObject



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

def completion_url = '/v1/messages'

#embed(**_provider_options) ⇒ Object

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 53

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

#headersObject



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

def headers
  {
    'x-api-key' => config.anthropic_api_key,
    'anthropic-version' => config.anthropic_version || '2023-06-01'
  }.compact
end

#list_modelsObject



57
58
59
60
61
62
63
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 57

def list_models(**)
  log.debug { 'listing available Anthropic models' }
  super.tap do |models|
    log.debug { "discovered #{Array(models).size} Anthropic model(s); publishing to registry" }
    self.class.registry_publisher.publish_models_async(models, readiness: readiness(live: false))
  end
end

#models_urlObject



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

def models_url = '/v1/models'

#stream_urlObject



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

def stream_url = completion_url