Class: OmniAI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/omniai/client.rb

Overview

An abstract class that must be subclassed (e.g. OmniAI::OpenAI::Client).

Usage:

class OmniAI::OpenAI::Client < OmniAI::Client
  def initialize(api_key: ENV.fetch('OPENAI_API_KEY'), logger: nil)
    super
  end
end

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, logger: nil) ⇒ Client

Returns a new instance of Client.

Parameters:

  • api_key (String)
  • logger (Logger) (defaults to: nil)


20
21
22
23
# File 'lib/omniai/client.rb', line 20

def initialize(api_key:, logger: nil)
  @api_key = api_key
  @logger = logger
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



16
17
18
# File 'lib/omniai/client.rb', line 16

def api_key
  @api_key
end

Instance Method Details

#chat(messages, model:, temperature: nil, format: nil, stream: nil) ⇒ OmniAI::Chat::Completion

Parameters:

  • messages (String, Array, Hash)
  • model (String)

    optional

  • format (Symbol) (defaults to: nil)

    optional :text or :json

  • temperature (Float, nil) (defaults to: nil)

    optional

  • stream (Proc, nil) (defaults to: nil)

    optional

Returns:

Raises:



45
46
47
# File 'lib/omniai/client.rb', line 45

def chat(messages, model:, temperature: nil, format: nil, stream: nil)
  raise NotImplementedError, "#{self.class.name}#chat undefined"
end

#connectionHTTP::Client

Returns:

  • (HTTP::Client)

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/omniai/client.rb', line 32

def connection
  raise NotImplementedError, "#{self.class.name}#connection undefined"
end

#inspectString

Returns:

  • (String)


26
27
28
29
# File 'lib/omniai/client.rb', line 26

def inspect
  masked_api_key = "#{api_key[..2]}***" if api_key
  "#<#{self.class.name} api_key=#{masked_api_key.inspect}>"
end

#transcribe(file, model:, language: nil, prompt: nil, temperature: nil, format: nil) ⇒ Object

Parameters:

  • file (IO)
  • model (String)
  • language (String, nil) (defaults to: nil)

    optional

  • prompt (String, nil) (defaults to: nil)

    optional

  • temperature (Float, nil) (defaults to: nil)

    optional

  • format (Symbol) (defaults to: nil)

    :text, :srt, :vtt, or :json (default)

Raises:



59
60
61
# File 'lib/omniai/client.rb', line 59

def transcribe(file, model:, language: nil, prompt: nil, temperature: nil, format: nil)
  raise NotImplementedError, "#{self.class.name}#speak undefined"
end