Skip to content

Conversation

@CorieW
Copy link
Member

@CorieW CorieW commented Sep 10, 2025

Resolves #3452

Checklist (if applicable):

  • Tested (manually, unit tested, etc.)

@CorieW CorieW force-pushed the @invertase/migrate-googlegenai-plugin branch 8 times, most recently from 2f8295a to eb9aa5f Compare September 15, 2025 20:00
@cabljac cabljac requested a review from Copilot September 16, 2025 09:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates the Google Genkit plugin from the v1 to v2 API, refactoring how models, embedders, and background models are defined and managed. The migration simplifies the plugin architecture by removing the explicit Genkit instance parameter and transitioning to a more functional approach.

  • Rename model() functions to createModelRef() for consistency
  • Migrate from v1 plugin architecture to v2 with updated initialization and resolution patterns
  • Update function signatures to remove Genkit instance parameters and return action objects directly

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
js/plugins/google-genai/tests/vertexai/veo_test.ts Update test mocks and function calls for v2 API migration
js/plugins/google-genai/tests/vertexai/lyria_test.ts Replace model() calls with createModelRef() and update defineModel calls
js/plugins/google-genai/tests/vertexai/index_test.ts Update test assertions and function calls for v2 API changes
js/plugins/google-genai/tests/vertexai/imagen_test.ts Replace model function references and update defineModel signature
js/plugins/google-genai/tests/vertexai/gemini_test.ts Update createModelRef calls and remove Genkit parameter from defineModel
js/plugins/google-genai/tests/vertexai/embedder_test.ts Update defineEmbedder calls to remove Genkit parameter
js/plugins/google-genai/tests/googleai/veo_test.ts Replace model() with createModelRef() and update test setup
js/plugins/google-genai/tests/googleai/index_test.ts Update test structure for v2 plugin API and function renaming
js/plugins/google-genai/tests/googleai/imagen_test.ts Replace model calls with createModelRef and update defineModel signature
js/plugins/google-genai/tests/googleai/gemini_test.ts Update function calls and remove Genkit parameters from model definitions
js/plugins/google-genai/tests/googleai/embedder_test.ts Update embedder definition calls to remove Genkit parameter
js/plugins/google-genai/src/vertexai/veo.ts Implement v2 API with createModelRef and backgroundModel functions
js/plugins/google-genai/src/vertexai/lyria.ts Migrate to v2 API removing Genkit parameter and using model function
js/plugins/google-genai/src/vertexai/index.ts Complete plugin migration to v2 architecture with new init/resolve pattern
js/plugins/google-genai/src/vertexai/imagen.ts Update to v2 API with createModelRef and model function
js/plugins/google-genai/src/vertexai/gemini.ts Migrate gemini models to v2 API and remove Genkit parameters
js/plugins/google-genai/src/vertexai/embedder.ts Update embedder implementation for v2 API with new function signatures
js/plugins/google-genai/src/googleai/veo.ts Implement v2 changes with createModelRef and backgroundModel
js/plugins/google-genai/src/googleai/index.ts Complete googleAI plugin migration to v2 architecture
js/plugins/google-genai/src/googleai/imagen.ts Update imagen models to v2 API pattern
js/plugins/google-genai/src/googleai/gemini.ts Migrate gemini implementation to v2 API structure
js/plugins/google-genai/src/googleai/embedder.ts Update embedder for v2 API with new function signatures

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@cabljac cabljac left a comment

Choose a reason for hiding this comment

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

lgtm, make sure to test in dev UI to ensure we're not changing the display names of anything (same goes for all model plugin migrations)

@cabljac cabljac self-requested a review September 16, 2025 09:58
Copy link
Contributor

@cabljac cabljac left a comment

Choose a reason for hiding this comment

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

generally lgtm - one comment about an any we've introduced, would rather not.

@CorieW CorieW force-pushed the @invertase/migrate-googlegenai-plugin branch from eb9aa5f to 3a8d64a Compare September 16, 2025 15:43
@CorieW CorieW marked this pull request as ready for review September 19, 2025 00:43
@pavelgj pavelgj requested a review from ifielker September 23, 2025 19:52
Copy link
Collaborator

@ifielker ifielker left a comment

Choose a reason for hiding this comment

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

I only reviewed the googleai part. I assume you did similar things for vertexai, so once you apply the comments to both I'll have a look again.

(In general, please do not change the existing logic or structure or naming if possible. This has been crafted and tested very carefully and thoroughly. I'm finding all sorts of random logic changes and you need to put them all back the way they were so it's not broken or wrong.)

@CorieW CorieW force-pushed the @invertase/migrate-googlegenai-plugin branch from c28612f to 5596504 Compare September 25, 2025 09:06
@CorieW
Copy link
Member Author

CorieW commented Sep 25, 2025

@ifielker 🤦‍♂️ All good points here. I've definitely overcomplicated this when I was unfamiliar with migrating.

I've made the changes, so hopefully now it should be as you'd expect. I'll also double check my other migrations to make sure I haven't done something similar with those.

@CorieW CorieW force-pushed the @invertase/migrate-googlegenai-plugin branch from 5596504 to 3efe1e1 Compare September 25, 2025 09:10
@CorieW CorieW force-pushed the @invertase/migrate-googlegenai-plugin branch from 3efe1e1 to 14a0263 Compare September 25, 2025 09:14
Copy link
Collaborator

@ifielker ifielker left a comment

Choose a reason for hiding this comment

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

I stopped my review partway through again. I'll pick up where I left off once you address these comments.

export type KnownModels = keyof typeof KNOWN_MODELS; // For autocomplete

export function model(
export function createEmbedderRef(
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to rename this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just basing it on #3542 (comment). Also, it seems more obvious to me that it would follow the same pattern used everywhere else in the code. I am aware that you've suggested importing model as pluginModel to avoid these name changes, but doesn't the name createModelRef/createEmbedderRef provide a clearer description of what the function does?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @CorieW let's pair up on this and review today

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @ifielker we're happy to revert to the original internal name model here if you prefer.

Originally I think the change to add the Ref suffix came from looking at the compat-openai plugin example (although that naming doesn't use create in it either actually, i think it uses e.g openAIModelRef etc for factories like this.)

Copy link
Contributor

Choose a reason for hiding this comment

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

the public API has model return a reference so also it'd be good to have consistency and keep it as model

import { GenkitPlugin, genkitPlugin } from 'genkit/plugin';
import { ActionType } from 'genkit/registry';
import { listModels } from './client.js';
import { EmbedderReference, ModelReference, z } from 'genkit';
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are 3 groups of imports:

  1. things imported from non-local files (that don't end in .js)
  2. model imports: "import * as ... "
  3. things imported from local files (that end in .js)

Please keep them organized the same way.

Copy link
Member Author

@CorieW CorieW Sep 25, 2025

Choose a reason for hiding this comment

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

Ah, I see. Which is your preference:

  1. Keep them the same as googleai index.ts and vertexai index.ts.
  2. Organise them as you've suggested.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the code and organised the imports as you've outlined.

@CorieW CorieW force-pushed the @invertase/migrate-googlegenai-plugin branch from 3f4a9bb to 7068764 Compare September 25, 2025 23:57
@CorieW CorieW force-pushed the @invertase/migrate-googlegenai-plugin branch from 7068764 to fc0f970 Compare September 25, 2025 23:59
@cabljac cabljac self-requested a review September 26, 2025 08:52
@cabljac
Copy link
Contributor

cabljac commented Sep 26, 2025

Some tests seem to need fixing, investigating this now.

@CorieW
Copy link
Member Author

CorieW commented Sep 29, 2025

Closing in favour of #3649

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

refactor: migrate google-genai plugin to V2 Plugin API

4 participants