Class: I18nAi::Clients::OpenAiClient
- Inherits:
-
BaseClient
- Object
- BaseClient
- I18nAi::Clients::OpenAiClient
- Defined in:
- lib/i18n_ai/clients/open_ai_client.rb
Instance Attribute Summary
Attributes inherited from BaseClient
Instance Method Summary collapse
- #chat(locale, text) ⇒ Object
-
#initialize ⇒ OpenAiClient
constructor
A new instance of OpenAiClient.
Methods inherited from BaseClient
Constructor Details
#initialize ⇒ OpenAiClient
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 |