Skip to content

Commit d285f99

Browse files
committed
fix(ai): Only include unexpected prediction element in error message.
If the `responseJson` from the Predict request has an image, the entire image base64 will be included in the error message. This can make the error message >400kB (!!), which could cause performance issues in apps. I ran into this when testing #9216, since the `safetyAttributes` would be included in a response and trigger this error, but the `predictions` array in `responseJson` would have images. I noticed that when the sample app rendered the `error.message`, it began running into serious performance issues.
1 parent 2058432 commit d285f99

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

.changeset/calm-guests-pump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/ai': patch
3+
---
4+
5+
Fixed an issue where `AIError` messages were too long after including an entire response body.

packages/ai/src/requests/response-helpers.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,7 @@ export async function handlePredictResponse<
299299
} else {
300300
throw new AIError(
301301
AIErrorCode.RESPONSE_ERROR,
302-
`Predictions array in response has missing properties. Response: ${JSON.stringify(
303-
responseJson
304-
)}`
302+
`Unexpected element in 'predictions' array in response: '${prediction}'`
305303
);
306304
}
307305
}

0 commit comments

Comments
 (0)