patterns-ai-core / langchainrb

Build LLM-powered applications in Ruby
https://rubydoc.info/gems/langchainrb
MIT License
1.3k stars 181 forks source link

Send nonCamelCased tools params #718

Closed Rukomoynikov closed 1 month ago

Rukomoynikov commented 2 months ago

Google Gemini or better say news_retriever tool didn't work due to the updates in the list of arguments. See the error message:

E, [2024-07-30T08:05:04.021082 #6] ERROR -- : [Langchain.rb] Error running tools: unknown keyword: :sortBy; /usr/src/app/lib/langchain/tool/news_retriever.rb:61:in
andreibondarev commented 1 month ago

@Rukomoynikov I'll take a look at this a bit later today.

Rukomoynikov commented 1 month ago

@Rukomoynikov I'll take a look at this a bit later today.

Sure. Here is a simple way to reproduce and confirm the bug:

  1. Switch to main branch
  2. In order to check parameters sent to Google add byebug\debugger to https://github.com/patterns-ai-core/langchainrb/blob/89a2cbffec353a2f4eeafb92318e2c41e035b45b/lib/langchain/llm/google_gemini.rb#L101
  3. Get into console with gem's code available (bin/console) and run this:
    
    llm = Langchain::LLM::GoogleGemini.new(api_key: 'api_key')
    news_retriever = Langchain::Tool::NewsRetriever.new(api_key: 'api_key')

Langchain::Assistant.new( llm: llm, tools: [news_retriever], instructions: 'You are a news reporter.' ).add_message_and_run content:"What's are latest news on the 2024 elections?",auto_tool_execution: true


----
So, expected params sent to Google should contain `sort_by`. But since the method below recursively converts all hash keys to camelCase it sends `sortBy`.
https://github.com/patterns-ai-core/langchainrb/blob/89a2cbffec353a2f4eeafb92318e2c41e035b45b/lib/langchain/llm/google_gemini.rb#L65
andreibondarev commented 1 month ago

@Rukomoynikov Yep, you're right, this is definitely a bug:

[3] pry(#<Langchain::LLM::GoogleGemini>)> Langchain::Utils::HashTransformer.camelize_lower("sort_by").to_sym
=> :sortBy
andreibondarev commented 1 month ago

@Rukomoynikov I think it was an oversight on my side to let this change go through: https://github.com/patterns-ai-core/langchainrb/pull/665#discussion_r1634024204

I think just reverting that one change would be the proper fix.

andreibondarev commented 1 month ago

@Rukomoynikov Closing this PR as I fixed it here: https://github.com/patterns-ai-core/langchainrb/pull/723