Sha256: 6740dfa426c23695de4e5e065d7b4c4330fa66bf768218e50b579754923ce1bd

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module OmniAI
  # 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
  #
  #     @return [OmniAI::OpenAI::Chat]
  #     def chat
  #       # TODO: implement
  #     end
  #   end
  class Client
    class Error < StandardError; end

    attr_accessor :api_key

    # @param api_key [String]
    # @param logger [Logger]
    def initialize(api_key:, logger: nil)
      @api_key = api_key
      @logger = logger
    end

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

    # @return [HTTP::Client]
    def connection
      raise NotImplementedError, "#{self.class.name}#connection undefined"
    end

    # @return [OmniAI::Chat] an instance of OmniAI::Chat
    def chat
      raise NotImplementedError, "#{self.class.name}#chat undefined"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniai-1.0.0 lib/omniai/client.rb