Module: BxBuilderChain::DependencyHelper

Included in:
Llm::Base, Processors::Base, Vectorsearch::Base
Defined in:
lib/bx_builder_chain/dependency_helper.rb

Defined Under Namespace

Classes: VersionError

Instance Method Summary collapse

Instance Method Details

#depends_on(gem_name) ⇒ Boolean

This method requires and loads the given gem, and then checks to see if the version of the gem meets the requirements listed in ‘langchain.gemspec` This solution was built to avoid auto-loading every single gem in the Gemfile when the developer will mostly likely be only using a few of them.

Parameters:

  • gem_name (String)

    The name of the gem to load

Returns:

  • (Boolean)

    Whether or not the gem was loaded successfully

Raises:

  • (LoadError)

    If the gem is not installed

  • (VersionError)

    If the gem is installed, but the version does not meet the requirements



15
16
17
18
19
20
# File 'lib/bx_builder_chain/dependency_helper.rb', line 15

def depends_on(gem_name)
  Gem::Specification.find_by_name(gem_name)
  true
rescue LoadError
  raise LoadError, "!Could not load #{gem_name}. Please ensure that the #{gem_name} gem is installed."
end