Sha256: ec8032adfc43d8d23024f390bfc2974504beda048e9fbea6545f9c792d77f9d2

Contents?: true

Size: 632 Bytes

Versions: 2

Compression:

Stored size: 632 Bytes

Contents

# frozen_string_literal: true

module GenAI
  class Chat
    extend Forwardable

    def_delegators :@chat, :start, :message, :history

    def initialize(provider, token, options: {})
      build_chat(provider, token, options)
    end

    private

    def build_chat(provider, token, options)
      klass = GenAI::Chat.constants.find do |const|
        const.to_s.downcase == provider.to_s.downcase.gsub('_', '')
      end

      raise UnsupportedProvider, "Unsupported Chat provider '#{provider}'" unless klass

      @chat = GenAI::Chat.const_get(klass).new(provider: provider, token: token, options: options)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gen-ai-0.4.3 lib/gen_ai/chat.rb
gen-ai-0.4.2 lib/gen_ai/chat.rb