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 Method Summary collapse

Instance Method Summary collapse

Class Method Details

.capabilitiesObject



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

def capabilities = Capabilities

.configuration_optionsObject



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

def configuration_options = %i[anthropic_api_key anthropic_api_base anthropic_version]

.configuration_requirementsObject



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

def configuration_requirements = %i[anthropic_api_key]

.slugObject



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

def slug = 'anthropic'

Instance Method Details

#api_baseObject



29
30
31
# File 'lib/legion/extensions/llm/anthropic/provider.rb', line 29

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

#completion_urlObject



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

def completion_url = '/v1/messages'

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

Raises:

  • (NotImplementedError)


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

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

#headersObject



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

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

#models_urlObject



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

def models_url = '/v1/models'

#stream_urlObject



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

def stream_url = completion_url