Class: I18nAi::Clients::OpenAiClient

Inherits:
BaseClient show all
Defined in:
lib/i18n_ai/clients/open_ai_client.rb

Instance Attribute Summary

Attributes inherited from BaseClient

#config

Instance Method Summary collapse

Methods inherited from BaseClient

#translate_content

Constructor Details

#initializeOpenAiClient

Returns a new instance of OpenAiClient.



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

def initialize
  super
  @client = OpenAI::Client.new(
    access_token: config[:access_token],
    log_errors: true
  )
end

Instance Method Details

#chat(locale, text) ⇒ Object



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

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