Firebase ai crashes after returning result from function call
Closed this issue · 2 comments
I have an application running @angular/fire and latest version of firebase/ai.
I'm using the gemini-2.5-flash-lite model, and it often crashes after reading the response of a function call.
It seems the specific referenced code is causing the crash as it assumes "parts" are present in the response, which is it not in this case:
// videoMetadata is not supported.
// Throw early since developers may send a long video as input and only expect to pay
// for inference on a small portion of the video.
if (
candidate.content?.parts?.some(
part => (part as InlineDataPart)?.videoMetadata
)
) {
The stacktrace in my browser is:
Error sending message to chat: TypeError: Cannot read properties of undefined (reading 'some')
at index.esm2017.js:1397:88
at Array.forEach (<anonymous>)
at mapGenerateContentCandidates (index.esm2017.js:1378:20)
at mapGenerateContentResponse (index.esm2017.js:1339:15)
at processGenerateContentResponse (index.esm2017.js:1655:16)
at async generateContent (index.esm2017.js:1646:37)
at async _ChatSession.sendMessage (index.esm2017.js:1963:9)
at async _AgAgentService.ask (ag-agent.ts:122:20)
The actual response from the model is:
{
"candidates": [
{
"content": {
"role": "model"
},
"finishReason": "STOP",
"index": 0
}
],
"usageMetadata": {
"promptTokenCount": 4911,
"totalTokenCount": 4911,
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 4911
}
]
},
"modelVersion": "gemini-2.5-flash-lite",
"responseId": "O28KafTmAtC-vdIP357P0Qg"
}
I guess the model should return a textual response also, which it does not do in this case.
I see a similar (if not the same) issue is referenced here:
https://discuss.ai.google.dev/t/gemini-2-5-pro-with-empty-response-text/81175
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.