Bundler inline is broken because of dependency loader
When I try to use langchain in inline bundler it breaks:
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
ruby '3.1.4'
gem 'langchainrb', '~> 0.9.4'
gem 'pdf-reader', '~> 1.4'
gem 'pg'
gem 'pgvector'
gem 'faraday'
gem 'sequel'
end
require 'langchain'
require 'forwardable'
llm = Langchain::LLM::Ollama.new(
url: OLLAMA_URL,
default_options: {
completion_model_name: 'llama2',
embeddings_model_name: 'llama2'
}
)
I managed to get it temporarily fixed with:
Langchain::DependencyHelper.class_eval do # fix for bundler/inline
def depends_on(gem_name, req: true)
require gem_name
end
end
But the initial error message looks like this:
/Users/pptasinski/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/bundler-2.5.6/lib/bundler/shared_helpers.rb:21:in `default_gemfile': Could not locate Gemfile (Bundler::GemfileNotFound)
from /Users/pptasinski/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/bundler-2.5.6/lib/bundler/shared_helpers.rb:26:in `default_lockfile'
from /Users/pptasinski/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/bundler-2.5.6/lib/bundler.rb:461:in `default_lockfile'
from /Users/pptasinski/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/bundler-2.5.6/lib/bundler.rb:205:in `definition'
from /Users/pptasinski/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/bundler-2.5.6/lib/bundler.rb:191:in `load'
from /Users/pptasinski/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/langchainrb-0.9.4/lib/langchain/dependency_helper.rb:23:in `depends_on'
from /Users/pptasinski/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/langchainrb-0.9.4/lib/langchain/llm/ollama.rb:37:in `initialize'
from app.rb:55:in `new'
from app.rb:55:in `<main>'
@ipepe Do you have any good ideas for a fix here?
Not really. Maybe it would be possible to detect that bundler/inline is loaded and depends_on shouldn't use that part of bundler that depends on Gemfile?
Hi both
I tried last version (main) of the gem and couldn't reproduce the bug. Not sure what exactly has helped. Maybe the ruby version, as I'm using never ruby version (3.3.4).
My ruby inline script:
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
ruby '3.3.4'
gem 'langchainrb', path: './'
gem 'pdf-reader', '~> 1.4'
gem 'pg'
gem 'pgvector'
gem 'faraday'
gem 'sequel'
end
require 'langchain'
require 'forwardable'
llm = Langchain::LLM::Ollama.new(
url: 'http://host.docker.internal:11434',
default_options: {
completion_model_name: 'llama3.1',
embeddings_model_name: 'llama3.1'
}
)
p llm.summarize text: "A big cat by Banksy appeared, poised ready to pounce, on a bare wooden advertising hoarding on Edgware Road in Cricklewood, north-west London, on Saturday."
And response in console:
root@7baf912223c4:/usr/src/app# ruby inline.rb
Fetching gem metadata from https://rubygems.org/.......
Resolving dependencies...
I, [2024-08-10T14:01:08.441997 #794] INFO -- request: POST http://host.docker.internal:11434/api/generate
I, [2024-08-10T14:01:08.442041 #794] INFO -- request: User-Agent: "Faraday v2.10.1"
Content-Type: "application/json"
I, [2024-08-10T14:01:08.442050 #794] INFO -- request: {"prompt":"Write a concise summary of the following TEXT. Do not include the word summary, just provide the summary.\n\nTEXT: A big cat by Banksy appeared, poised ready to pounce, on a bare wooden advertising hoarding on Edgware Road in Cricklewood, north-west London, on Saturday.\n\nCONCISE SUMMARY:\n","model":"llama3.1","stream":false,"options":{"temperature":0.0}}
I, [2024-08-10T14:01:13.299834 #794] INFO -- response: Status 200
I, [2024-08-10T14:01:13.316055 #794] INFO -- response: content-type: "application/json; charset=utf-8"
date: "Sat, 10 Aug 2024 14:01:13 GMT"
content-length: "852"
I, [2024-08-10T14:01:13.324356 #794] INFO -- response:
#<Langchain::LLM::OllamaResponse:0x0000ffff65039ca0 @prompt_tokens=nil, @raw_response={"model"=>"llama3.1", "created_at"=>"2024-08-10T14:01:12.966881Z", "response"=>"A new Banksy artwork, featuring a large cat, was installed on an advertising hoarding in northwest London.", "done"=>true, "done_reason"=>"stop", "context"=>[128009, 128006, 882, 128007, 271, 8144, 264, 64694, 12399, 315, 279, 2768, 16139, 13, 3234, 539, 2997, 279, 3492, 12399, 11, 1120, 3493, 279, 12399, 382, 12998, 25, 362, 2466, 8415, 555, 38866, 88, 9922, 11, 54946, 5644, 311, 281, 9933, 11, 389, 264, 12743, 23162, 13172, 11640, 29510, 389, 3279, 70, 1698, 9728, 304, 4656, 26688, 6798, 11, 10411, 38702, 7295, 11, 389, 7884, 382, 5910, 34, 9311, 96885, 512, 128009, 128006, 78191, 128007, 271, 32, 502, 38866, 88, 29409, 11, 16850, 264, 3544, 8415, 11, 574, 10487, 389, 459, 13172, 11640, 29510, 304, 53342, 7295, 13], "total_duration"=>4515482541, "load_duration"=>46927708, "prompt_eval_count"=>77, "prompt_eval_duration"=>2062662000, "eval_count"=>23, "eval_duration"=>2395670000}, @model="llama3.1">
@Rukomoynikov Thank you for glancing this over!
@ipepe I'm closing this ticket for now unless you "re-raise" this issue! Thanks!