- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 33
 
Description
We have a gem that includes langchainrb and ruby-openai as a runtime dependency in a gemspec:
  spec.add_dependency 'langchainrb', '~> 0.19.4'
  spec.add_dependency 'ruby-openai', '~> 7.4.0'
We have another (rails) project that depends on our gem.
We are finding that unless we explicitly add the ruby-openai dependency to our top level rails project then Langchain::LLM::OpenAI won't be able to load the OpenAI client.
Below is a console session that illustrates this:
[1] pry(main)> require 'openai'
=> true
[2] pry(main)> OpenAI::Client.new
=> #<OpenAI::Client:86760 @access_token=[REDACTED], @admin_token=[REDACTED], @api_type=nil, @api_version="v1", @extra_headers=[REDACTED], @log_errors=false, @organization_id=[REDACTED], @request_timeout=120, @uri_base="https://api.openai.com/", @faraday_middleware=nil>
[3] pry(main)> Object.new.extend(Langchain::DependencyHelper).depends_on('ruby-openai')
Langchain::DependencyHelper::LoadError: Could not load ruby-openai. Please ensure that the ruby-openai gem is installed.
from /usr/share/rvm/gems/ruby-3.1.2@m3/gems/langchainrb-0.19.4/lib/langchain/dependency_helper.rb:38:in `rescue in depends_on'
Caused by Langchain::DependencyHelper::LoadError: Langchain::DependencyHelper::LoadError
from /usr/share/rvm/gems/ruby-3.1.2@m3/gems/langchainrb-0.19.4/lib/langchain/dependency_helper.rb:25:in `depends_on'
I think that the following code in the DependencyHelper is only able to validate that a required gem is in the top-level Gemfile, and can't deal with (transitive) dependencies through other gems:
   gem_requirement = Bundler.load.dependencies.find { |g| g.name == gem_name }&.requirement
   raise LoadError unless gem_requirement
Let me know if this is by design, or if I am otherwise missing something?
It is pretty easy to workaround by adding the explicit dependency to the top level project, just wasn't expecting to need to do that.