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

Inherits:
Provider
  • Object
show all
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



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

def registry_publisher
  @registry_publisher ||= RegistryPublisher.new
end

Class Method Details

.capabilitiesObject



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

def capabilities = Capabilities

.configuration_optionsObject



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

def configuration_options = %i[anthropic_api_key anthropic_api_base anthropic_version]

.configuration_requirementsObject



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

def configuration_requirements = %i[anthropic_api_key]

.slugObject



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

def slug = 'anthropic'

Instance Method Details

#api_baseObject



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

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

#completion_urlObject



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

def completion_url = '/v1/messages'

#embed(_text, model:, dimensions:) ⇒ Object

Raises:

  • (NotImplementedError)


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

def embed(_text, model:, dimensions:)
  raise NotImplementedError, 'Anthropic does not expose embeddings through this provider'
end

#headersObject



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

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

#list_modelsObject



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

def list_models
  super.tap do |models|
    self.class.registry_publisher.publish_models_async(models, readiness: readiness(live: false))
  end
end

#models_urlObject



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

def models_url = '/v1/models'

#stream_urlObject



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

def stream_url = completion_url