the following conditional would always submit a tool, since the array has a single element:
api_response = self.generate_with_backoff(
client=client,
contents=inference_data["message"],
generation_config=GenerationConfig(
temperature=self.temperature,
),
tools=tools if len(tools) > 0 else None, # conditional will always resolve to True
)
This led to the following Gemini API error when a Tool was submitted with no function declarations:
400 Request contains an invalid argument. [detail: "[ORIGINAL ERROR] generic::invalid_argument: The GenerateContentRequest proto is invalid:\n * tools[0].tool_type: required one_of \'tool_type\' must have one initialized field"
The fix moves the conditional to the creation of the tools array:
if func_declarations:
tools = [Tool(function_declarations=func_declarations)]
else:
tools = None
There is a bug in handling examples with no tools / function definitions. Because the tools array is created like this:
the following conditional would always submit a tool, since the array has a single element:
This led to the following Gemini API error when a Tool was submitted with no function declarations:
The fix moves the conditional to the creation of the tools array: