Class: Riffer::Providers::OpenAI

Inherits:
Base
  • Object
show all
Defined in:
lib/riffer/providers/open_ai.rb

Instance Method Summary collapse

Methods inherited from Base

find, #generate_text, identifier, #stream_text

Methods included from Messages::Converter

#convert_to_message_object

Constructor Details

#initialize(**options) ⇒ OpenAI

Initializes the OpenAI provider.

Parameters:

  • options (Hash)

    optional client options. Use ‘:api_key` to override `Riffer.config.openai.api_key`.

Raises:

  • (Riffer::ArgumentError)

    if an API key is not provided either via ‘:api_key` or `Riffer.config.openai.api_key`.



11
12
13
14
15
16
17
18
# File 'lib/riffer/providers/open_ai.rb', line 11

def initialize(**options)
  depends_on "openai"

  api_key = options.fetch(:api_key, Riffer.config.openai.api_key)
  raise Riffer::ArgumentError, "OpenAI API key is required. Set it via Riffer.configure or pass :api_key option" if api_key.nil? || api_key.empty?

  @client = ::OpenAI::Client.new(api_key: api_key, **options.except(:api_key))
end