patterns-ai-core / langchainrb

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

Calling Google Gemini when Assistant uses NewsRetriever tool throws an error. #696

Closed andreibondarev closed 2 months ago

andreibondarev commented 4 months ago

Describe the bug An HTTP error is thrown. I debugged a bit, and it looks like there's an issue with what's being passed in via tools:.

To Reproduce

llm = Langchain::LLM::GoogleGemini.new(api_key: ENV['GOOGLE_GEMINI_API_KEY'])

a = Langchain::Assistant.new(
  llm: llm,
  tools: [Langchain::Tool::NewsRetriever.new(api_key: ENV['NEWS_API_KEY'])],
  instructions: 'You are a news reporter.'
)

a.add_message_and_run content:"What's are latest news on the 2024 elections?", auto_tool_execution: true
/Users/andrei/Code/langchain/lib/langchain/llm/google_gemini.rb:79:in `chat': #<Net::HTTPBadRequest:0x0000000124077310> (StandardError)
    from /Users/andrei/Code/langchain/lib/langchain/assistants/assistant.rb:281:in `chat_with_llm'
    from /Users/andrei/Code/langchain/lib/langchain/assistants/assistant.rb:213:in `handle_user_or_tool_message'
    from /Users/andrei/Code/langchain/lib/langchain/assistants/assistant.rb:180:in `process_latest_message'
    from /Users/andrei/Code/langchain/lib/langchain/assistants/assistant.rb:162:in `handle_state'
    from /Users/andrei/Code/langchain/lib/langchain/assistants/assistant.rb:93:in `run'
    from /Users/andrei/Code/langchain/lib/langchain/assistants/assistant.rb:105:in `add_message_and_run'
    from (irb):9:in `<main>'
    from <internal:kernel>:187:in `loop'
    from bin/console:51:in `<main>'

Expected behavior Google Gemini successfully returns the LLM call and the Assistant execution continues.

Desktop (please complete the following information):

Rukomoynikov commented 3 months ago

Addressed in https://github.com/patterns-ai-core/langchainrb/pull/718