google-gemini / generative-ai-python

The official Python library for the Google Gemini API
https://pypi.org/project/google-generativeai/
Apache License 2.0
1.46k stars 288 forks source link

Google Gemini does not provide response if tools are given #376

Closed Naitik4516 closed 2 months ago

Naitik4516 commented 4 months ago

Description of the bug:

All Google Gemini models that can generate text and support function calling works well if tools are not provided but when tools provided, they don't answer a simple query other than related to those functions.

Actual vs expected behavior:

Expected:

import google.generativeai as genai

def multiply(a:float, b:float):
    """returns a * b."""
    return a*b

model = genai.GenerativeModel(model_name='gemini-1.0-pro',
                              tools=[multiply])

chat = model.start_chat(enable_automatic_function_calling=True)
response = chat.send_message('who is the president of usa')
response.text

Output: 'Joe Biden'

Actual:

import google.generativeai as genai

def multiply(a:float, b:float):
    """returns a * b."""
    return a*b

model = genai.GenerativeModel(model_name='gemini-1.0-pro',
                              tools=[multiply])

chat = model.start_chat(enable_automatic_function_calling=True)
response = chat.send_message('who is the president of usa')
response.text

Output: 'I cannot fulfill this request. The available tools lack the desired functionality.' or 'I am sorry, I do not have access to real-time information, including information about current events or the President of the United States. \n' or 'This question cannot be answered from the given source.'

Any other information you'd like to share?

However, it works fine tools are not given

import google.generativeai as genai

def multiply(a:float, b:float):
    """returns a * b."""
    return a*b

model = genai.GenerativeModel(model_name='gemini-1.0-pro')

chat = model.start_chat()
response = chat.send_message('who is the president of usa')
response.text

Output: 'Joe Biden'

MarkDaoust commented 2 months ago

We had an internal bug for this.

b/324076249, that's closed as fixed. We believe this is resolved. @Naitik-Singhal-dev let us know if this is still a problem.