Skip to content

Commit 84b8bed

Browse files
authored
fix(ai): Only include unexpected prediction element in error message (#9222)
* 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 9b63cd6 commit 84b8bed

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,9 @@ export async function handlePredictResponse<
298298
} else {
299299
throw new AIError(
300300
AIErrorCode.RESPONSE_ERROR,
301-
`Predictions array in response has missing properties. Response: ${JSON.stringify(
302-
responseJson
303-
)}`
301+
`Unexpected element in 'predictions' array in response: '${JSON.stringify(
302+
prediction
303+
)}'`
304304
);
305305
}
306306
}

0 commit comments

Comments
 (0)