Module: Rager::Providers

Extended by:
T::Sig
Defined in:
lib/rager/providers.rb

Constant Summary collapse

PROVIDERS =
T.let({
  Rager::Operation::Chat => {
    openai: -> { Rager::Chat::Providers::Openai.new }
  },
  Rager::Operation::Embed => {
    openai: -> { Rager::Embed::Providers::Openai.new }
  },
  Rager::Operation::Rerank => {
    cohere: -> { Rager::Rerank::Providers::Cohere.new }
  },
  Rager::Operation::Image => {
    replicate: -> { Rager::Image::Providers::Replicate.new }
  },
  Rager::Operation::Mesh => {
    replicate: -> { Rager::Mesh::Providers::Replicate.new }
  },
  Rager::Operation::Template => {
    erb: -> { Rager::Template::Providers::Erb.new },
    mustache: -> { Rager::Template::Providers::Mustache.new }
  },
  Rager::Operation::Search => {
    jina: -> { Rager::Search::Providers::Jina.new }
  }
}, T::Hash[Rager::Operation, T::Hash[Symbol, T.proc.returns(T.untyped)]])

Class Method Summary collapse

Class Method Details

.get_provider(operation, key, options) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rager/providers.rb', line 47

def self.get_provider(operation, key, options)
  operation_providers = PROVIDERS[operation]

  unless operation_providers&.key?(key)
    raise Rager::Errors::OptionsError.new(
      options,
      ["provider"],
      details: "Unknown #{operation} provider: #{key}. Known providers: #{list_providers(operation).join(", ")}"
    )
  end

  T.must(operation_providers[key]).call
end

.list_providers(operation) ⇒ Object



36
37
38
# File 'lib/rager/providers.rb', line 36

def self.list_providers(operation)
  PROVIDERS.fetch(operation, {}).keys
end