Class: I18nAi::Clients::AnthropicClient

Inherits:
BaseClient
  • Object
show all
Defined in:
lib/i18n_ai/clients/anthropic_client.rb

Overview

The AnthropicClient class is responsible for interacting with the Anthropic API

Instance Attribute Summary

Attributes inherited from BaseClient

#config

Instance Method Summary collapse

Methods inherited from BaseClient

#translate_content

Constructor Details

#initializeAnthropicClient

Returns a new instance of AnthropicClient.



10
11
12
13
14
15
# File 'lib/i18n_ai/clients/anthropic_client.rb', line 10

def initialize
  super
  @client = Anthropic::Client.new(
    access_token: config[:access_token]
  )
end

Instance Method Details

#chat(locale, text) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/i18n_ai/clients/anthropic_client.rb', line 17

def chat(locale, text)
  response = @client.messages(
    parameters: {
      model: config[:model],
      messages: [{ role: "user", content: chat_prompt(locale, text) }],
      max_tokens: 4096
    }
  )
  parse_response(response)
end