Sha256: ec5819c62620646a4b5585789c4317379b19d033281c5b1d37e4543d47caef96

Contents?: true

Size: 640 Bytes

Versions: 7

Compression:

Stored size: 640 Bytes

Contents

# frozen_string_literal: true

require 'forwardable'

module GenAI
  class Language
    extend Forwardable

    def_delegators :@llm, :embed, :complete, :chat

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

    private

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

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

      @llm = GenAI::Language.const_get(klass).new(token: token, options: options)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gen-ai-0.4.3 lib/gen_ai/language.rb
gen-ai-0.4.2 lib/gen_ai/language.rb
gen-ai-0.4.1 lib/gen_ai/language.rb
gen-ai-0.4.0 lib/gen_ai/language.rb
gen-ai-0.4.0.alpha.3 lib/gen_ai/language.rb
gen-ai-0.4.0.alpha.2 lib/gen_ai/language.rb
gen-ai-0.4.0.alpha.1 lib/gen_ai/language.rb