Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotImplementedError: Langchain::LLM::GoogleGemini does not support generating embeddings (NotImplementedError) #752

Closed
palladius opened this issue Sep 2, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@palladius
Copy link
Contributor

API call should be:

curl "https://generativelanguage.googleapis.com/v1beta/models/text-embedding-004:embedContent?key=$GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"model": "models/text-embedding-004",
     "content": {
     "parts":[{
     "text": "Hello world"}]}, }' 2> /dev/null 

@palladius palladius added the bug Something isn't working label Sep 2, 2024
@andreibondarev
Copy link
Collaborator

andreibondarev commented Sep 2, 2024

@palladius Hmm... what is the Ruby code you're running? See below:

irb(main):003> llm = Langchain::LLM::GoogleGemini.new(api_key: ENV["GOOGLE_GEMINI_API_KEY"])
irb(main):004> llm.embed text: "Hello world"
=>
#<Langchain::LLM::GoogleGeminiResponse:0x000000010a8d4108
 @model="text-embedding-004",
 @raw_response=
  {"embedding"=>
    {"values"=>
      [0.013168523,
       -0.008711934,
       -0.046782676,
       ...

@palladius
Copy link
Contributor Author

I'm running ruby 3.2.1
I can confirm the same error with latest gem 0.15.4

irb(main):007> embedding = @llm.embed text: "Hello world"
/usr/local/google/home/ricc/.local/share/gem/ruby/3.2.0/gems/langchainrb-0.15.4/lib/langchain/llm/google_gemini.rb:96:in `embed': undefined method `URI' for #<Langchain::LLM::GoogleGemini:0x00007faed850c290 @api_key="REDACTED", @defaults={:chat_completion_model_name=>"gemini-1.5-pro-latest", :embeddings_model_name=>"text-embedding-004", :temperature=>0.0}, @chat_parameters=#<Langchain::LLM::UnifiedParameters:0x00007faed3a09108 @schema={:messages=>{}, :model=>{:default=>"gemini-1.5-pro-latest"}, :prompt=>{}, :system=>{}, :response_format=>{}, :stop=>{}, :stream=>{}, :max_tokens=>{}, :temperature=>{:default=>0.0}, :top_p=>{}, :top_k=>{}, :frequency_penalty=>{}, :presence_penalty=>{}, :repetition_penalty=>{}, :seed=>{}, :tools=>{:default=>[]}, :tool_choice=>{}, :logit_bias=>{}, :generation_config=>{:default=>nil}, :safety_settings=>{:default=>nil}, :contents=>{}, :system_instruction=>{}, :tool_config=>{}}, @aliases={}, @remapped={:messages=>:contents, :system=>:system_instruction, :tool_choice=>:tool_config}, @ignored=#<Set: {}>>> (NoMethodError)

      uri = URI("https://generativelanguage.googleapis.com/v1beta/models/#{model}:embedContent?key=#{api_key}")
            ^^^
        from (irb):7:in `<main>'
        from /usr/local/google/home/ricc/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/irb-1.14.0/exe/irb:9:in `<top (required)>'
        from /usr/local/google/home/ricc/.rbenv/versions/3.2.1/bin/irb:25:in `load'
        from /usr/local/google/home/ricc/.rbenv/versions/3.2.1/bin/irb:25:in `<main>'
irb(main):008> 

Another small thing: whenever I render @llm I get the api_key in output which makes it very EASY to publish the key on github by mistake. Is there a way t mark an attribute as private/password and make api_key such? Or do I have to rewrite the inspect function?

@palladius
Copy link
Contributor Author

trying again with 3.3.4:

irb(main):001> require 'langchain'
=> true
irb(main):002> RUBY_VERSION
=> "3.3.4"
irb(main):003> llm = Langchain::LLM::GoogleGemini.new(api_key: ENV["GEMINI_API_KEY"])
=> 
#<Langchain::LLM::GoogleGemini:0x00007fe718892b80
...
irb(main):004> llm.embed text: "Hello world"
/usr/local/google/home/ricc/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/langchainrb-0.15.4/lib/langchain/llm/google_gemini.rb:96:in `embed': undefined method `URI' for an instance of Langchain::LLM::GoogleGemini (NoMethodError)

      uri = URI("https://generativelanguage.googleapis.com/v1beta/models/#{model}:embedContent?key=#{api_key}")
            ^^^
        from (irb):4:in `<main>'
        from <internal:kernel>:187:in `loop'
        from /usr/local/google/home/ricc/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/irb-1.14.0/exe/irb:9:in `<top (required)>'
        from /usr/local/google/home/ricc/.rbenv/versions/3.3.4/bin/irb:25:in `load'
        from /usr/local/google/home/ricc/.rbenv/versions/3.3.4/bin/irb:25:in `<main>'

Same issue.

@palladius
Copy link
Contributor Author

even cleaning up all my gems and bundler with latest ruby i get the same:

rm -rf /usr/local/google/home/ricc/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/
rm -rf /usr/local/google/home/ricc/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/
gem install bundler
gem install irb
bundle install
irb

irb(main):001> require 'langchain'
=> true
irb(main):002> RUBY_VERSION
=> "3.3.4"
irb(main):003> llm = Langchain::LLM::GoogleGemini.new(api_key: ENV["GEMINI_API_KEY"])
=>
#<Langchain::LLM::GoogleGemini:0x00007fa5d7f97458
...
irb(main):004> llm.embed text: "Hello world"
/usr/local/google/home/ricc/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/langchainrb-0.15.4/lib/langchain/llm/google_gemini.rb:96:in `embed': undefined method `URI' for an instance of Langchain::LLM::GoogleGemini (NoMethodError)

      uri = URI("https://generativelanguage.googleapis.com/v1beta/models/#{model}:embedContent?key=#{api_key}")
            ^^^
        from (irb):4:in `<main>'
        from <internal:kernel>:187:in `loop'
        from /usr/local/google/home/ricc/.local/share/gem/ruby/3.3.0/gems/irb-1.14.0/exe/irb:9:in `<top (required)>'
        from /usr/local/google/home/ricc/.rbenv/versions/3.3.4/bin/irb:25:in `load'
        from /usr/local/google/home/ricc/.rbenv/versions/3.3.4/bin/irb:25:in `<main>'

I'll now try in a different computer.

@andreibondarev
Copy link
Collaborator

This bug was fixed with #754.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants