When using function calling, Gemini API sends a text response along with function call

When using function calling, Most of the time gemini API send the function call only. But sometimes, it sends text first and then call the function. I don’t want this behaviour. When invoking a function, I want the Gemini to send me function_name and parameters only.

How can I achieve this behaviour?

NOTE: I’m using StreamingResponse. Hence, I just can’t simply filter out text response. Current implementation of my app assumes that if we receive a text then it’s a response from Gemini and not a function call.

You can request it via system instructions, but to be 100% safe why not just filter it out from the response? It’s simple enough to get only the function call from the parts array.

I’m using StreamingResponse. Please view the updated description of original problem.

Tried using system instruction but didn’t get the results as expected.

I’ve been having this same problem, but I’m not using streaming. I’m just calling models.generateContent

I’m using the node GoogleGenAI from @google/genai.
Every model that I’ve tried so far has this problem.

This used to work last week. The past few days it’s gotten worse, so much so that today it’s failed to call a function 100% of the time.

I’m about to jump ship from Google. :frowning: