From 7e402fb3d73d0af150f0dbdd59ce045c4f17df6f Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Wed, 16 Oct 2024 17:36:49 -0400 Subject: [PATCH 1/2] Upgrade to mock responses v4 --- packages/vertexai/src/requests/response-helpers.ts | 1 + packages/vertexai/src/requests/stream-reader.ts | 4 +++- scripts/update_vertexai_responses.sh | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/vertexai/src/requests/response-helpers.ts b/packages/vertexai/src/requests/response-helpers.ts index 3521dc1bc5..0435f1711c 100644 --- a/packages/vertexai/src/requests/response-helpers.ts +++ b/packages/vertexai/src/requests/response-helpers.ts @@ -36,6 +36,7 @@ export function createEnhancedContentResponse( * The Vertex AI backend omits default values. * This causes the `index` property to be omitted from the first candidate in the * response, since it has index 0, and 0 is a default value. + * See: https://github.com/firebase/firebase-js-sdk/issues/8566 */ if (response.candidates && !response.candidates[0].hasOwnProperty('index')) { response.candidates[0].index = 0; diff --git a/packages/vertexai/src/requests/stream-reader.ts b/packages/vertexai/src/requests/stream-reader.ts index da8eca7188..8162407d90 100644 --- a/packages/vertexai/src/requests/stream-reader.ts +++ b/packages/vertexai/src/requests/stream-reader.ts @@ -151,7 +151,9 @@ export function aggregateResponses( for (const response of responses) { if (response.candidates) { for (const candidate of response.candidates) { - const i = candidate.index; + // Index will be undefined if it's the first index (0), so we should use 0 if it's undefined. + // See: https://github.com/firebase/firebase-js-sdk/issues/8566 + const i = candidate.index || 0; if (!aggregatedResponse.candidates) { aggregatedResponse.candidates = []; } diff --git a/scripts/update_vertexai_responses.sh b/scripts/update_vertexai_responses.sh index 27c32a09ea..fa11ef572f 100755 --- a/scripts/update_vertexai_responses.sh +++ b/scripts/update_vertexai_responses.sh @@ -17,7 +17,7 @@ # This script replaces mock response files for Vertex AI unit tests with a fresh # clone of the shared repository of Vertex AI test data. -RESPONSES_VERSION='v3.*' # The major version of mock responses to use +RESPONSES_VERSION='v4.*' # The major version of mock responses to use REPO_NAME="vertexai-sdk-test-data" REPO_LINK="https://github.com/FirebaseExtended/$REPO_NAME.git" From fad0613411f3ce2aa331d8d3370764c6bd4a05d3 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Wed, 16 Oct 2024 17:45:30 -0400 Subject: [PATCH 2/2] Upgrade from v4 to v5 mock responses --- scripts/update_vertexai_responses.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_vertexai_responses.sh b/scripts/update_vertexai_responses.sh index fa11ef572f..101eac90d9 100755 --- a/scripts/update_vertexai_responses.sh +++ b/scripts/update_vertexai_responses.sh @@ -17,7 +17,7 @@ # This script replaces mock response files for Vertex AI unit tests with a fresh # clone of the shared repository of Vertex AI test data. -RESPONSES_VERSION='v4.*' # The major version of mock responses to use +RESPONSES_VERSION='v5.*' # The major version of mock responses to use REPO_NAME="vertexai-sdk-test-data" REPO_LINK="https://github.com/FirebaseExtended/$REPO_NAME.git"