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_provider, #generate_text, identifier, #stream_text

Methods included from DependencyHelper

#depends_on

Constructor Details

#initialize(**options) ⇒ OpenAI

Returns a new instance of OpenAI.

Raises:

  • (ArgumentError)


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

def initialize(**options)
  depends_on "openai"

  api_key = options.fetch(:api_key, Riffer.config.openai.api_key)
  raise 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