Class: Seo::Providers::Anthropic

Inherits:
Base
  • Object
show all
Defined in:
lib/seo/providers/anthropic.rb

Constant Summary collapse

DEFAULT_MODEL =
"claude-sonnet-4-6"

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, model: DEFAULT_MODEL) ⇒ Anthropic

Returns a new instance of Anthropic.



11
12
13
14
# File 'lib/seo/providers/anthropic.rb', line 11

def initialize(api_key:, model: DEFAULT_MODEL)
  @client = ::Anthropic::Client.new(access_token: api_key)
  @model  = model
end

Instance Method Details

#complete(prompt, max_tokens:) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/seo/providers/anthropic.rb', line 16

def complete(prompt, max_tokens:)
  response = @client.messages(parameters: {
    model:      @model,
    max_tokens: max_tokens,
    messages:   [{ role: "user", content: prompt }]
  })
  response.dig("content", 0, "text").to_s
end