Google Gemini not provides response if tools are given

All Google Gemini models that can generate text and support function calling works well if tools are not provided
For example:

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’

But when i integrate tools in it and query something else than tool, the model not works well.

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 ‘This question cannot be answered from the given source.’

1 Like

Welcome to the forum. This matches the behavior I have observed. I can see from your code that you have not used the function calling configuration option (https://ai.google.dev/api/rest/v1beta/ToolConfig). When you do not specify an option, you get the default, which is function calling mode AUTO.

The model behaves poorly in AUTO mode. This is another report of this issue (The Gemini Pro function calling and normal questio... - Google Cloud Community) and ticket: Including Tools prevents Gemini from providing a natural language (generalized) response · Issue #3775 · googleapis/python-aiplatform · GitHub

You can control the behavior by selectively enabling or disabling the tools using the non - AUTO mode settings of the function calling mode.

Hope that helps.