Skip to content

refactor(generative-ai): migrate first batch of samples to @google/genai#4330

Open
angelcaamal wants to merge 7 commits into
mainfrom
refactor/migrate-vertexai-to-genai
Open

refactor(generative-ai): migrate first batch of samples to @google/genai#4330
angelcaamal wants to merge 7 commits into
mainfrom
refactor/migrate-vertexai-to-genai

Conversation

@angelcaamal
Copy link
Copy Markdown
Contributor

@angelcaamal angelcaamal commented Jun 2, 2026

Description

This PR migrates the first batch of generative AI samples (focusing on inference, count-tokens, function-calling, and grounding) from the legacy @google-cloud/vertexai SDK to the new unified @google/genai SDK.

  • Test Isolation: Temporarily applied .skip() to 17 remaining unmigrated tests to maintain a green CI pipeline. These are part of the batch strategy and will be fully refactored in part 2.

It also ensures the samples use updated, active model versions following recent deprecations.

Changes

  • SDK Migration: Refactored core samples to use the new unified @google/genai library instead of @google-cloud/vertexai.
  • Model Update: Replaced deprecated model references with gemini-2.5-flash across the migrated samples and test configurations.

Fixes Internal: b/518928211

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed guidelines from CONTRIBUTING.MD and Samples Style Guide
  • Tests pass: npm test (see Testing)
  • Lint pass: npm run lint (see Style)
  • Required CI tests pass (see CI testing)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This pull request is from a branch created directly off of GoogleCloudPlatform/nodejs-docs-samples. Not a fork.
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new sample directory, and I created GitHub Actions workflow for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

Note: Any check with (dev), (experimental), or (legacy) can be ignored and should not block your PR from merging (see CI testing).

@angelcaamal angelcaamal added samples Issues that are directly related to samples. generated: genai Contains Generative AI based code, requesting an additional reviewer. labels Jun 2, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates several generative AI Node.js snippets from the @google-cloud/vertexai SDK to the new @google/genai SDK, updating client initialization, request structures, and response handling for token counting, function calling, grounding, and inference. The review feedback suggests adding default values for projectId in inference samples to maintain repository consistency, fixing minor typos and grammar in comments, standardizing role names to lowercase, and removing redundant JSON.stringify calls.

Comment thread generative-ai/snippets/inference/nonStreamMultiModalityBasic.js
Comment thread generative-ai/snippets/inference/nonStreamTextBasic.js
Comment thread generative-ai/snippets/inference/streamMultiModalityBasic.js
Comment thread generative-ai/snippets/inference/streamTextBasic.js
Comment thread generative-ai/snippets/grounding/groundingPrivateDataBasic.js Outdated
Comment thread generative-ai/snippets/function-calling/functionCallingStreamContent.js Outdated
Comment thread generative-ai/snippets/grounding/groundingPublicDataBasic.js Outdated
Comment thread generative-ai/snippets/count-tokens/countTokensAdvanced.js Outdated
@angelcaamal angelcaamal marked this pull request as ready for review June 2, 2026 21:33
@angelcaamal angelcaamal requested review from a team as code owners June 2, 2026 21:33
Copy link
Copy Markdown
Contributor

@amcolin amcolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really appreciate it if this PR could be broken down into smaller, more manageable pieces, if that’s possible.

model: model,
// Initialize the client with your Cloud project and location
const client = new GoogleGenAI({
vertexai: true,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity why we are keeping this flag?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vertexai: true flag is a switch that tells the SDK: Connect to the enterprise version of Google Cloud.
If you leave it out, the code assumes you are a standard user and will ask for a traditional API Key

@@ -23,7 +23,7 @@ const projectId = process.env.CAIP_PROJECT_ID;
const location = process.env.LOCATION;
const model = 'gemini-2.0-flash-001';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we also need to change the model for the test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a large migration, I'm tackling it in batches. I've disabled these specific tests for now to keep the CI green, but they will be fully migrated in the second phase of this update.

@angelcaamal angelcaamal requested a review from amcolin June 2, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: genai generated: genai Contains Generative AI based code, requesting an additional reviewer. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants