Skip to content

refactor(go/plugins/googlegenai): update plugin structure#4414

Draft
apascal07 wants to merge 3 commits intomainfrom
ap/go-googlegenai
Draft

refactor(go/plugins/googlegenai): update plugin structure#4414
apascal07 wants to merge 3 commits intomainfrom
ap/go-googlegenai

Conversation

@apascal07
Copy link
Collaborator

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @apascal07, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a substantial internal refactoring of the Google GenAI plugin. The primary goal is to enhance code organization, maintainability, and consistency in how AI models, embedders, and their associated actions are managed. By centralizing model classification, action resolution, and specific utility functions into new, dedicated files, the changes aim to simplify future development and reduce complexity within the plugin's core logic.

Highlights

  • Plugin Action Management Refactor: The logic for listing and resolving actions (models and embedders) within the Google AI and Vertex AI plugins has been refactored into dedicated actions.go file, centralizing and streamlining how different model types (Gemini, Imagen, Veo, Embedders) are handled.
  • Model Type Classification: A new model_type.go file introduces a ModelType enum and ClassifyModel function to categorize models based on their names, providing a single source of truth for model classification and simplifying model-specific logic across the plugin.
  • Code Execution Handling: New types (CodeExecutionResult, ExecutableCode) and utility functions have been added in code_execution.go to better represent and extract code execution information from AI model responses.
  • Code Organization and Modularity: Significant portions of code related to embedder creation, schema translation, and tool handling have been moved from gemini.go to new, dedicated files (embedder.go, schema.go, tools.go), improving modularity and maintainability.
  • Deprecated Model/Embedder Lookups: Several direct model and embedder lookup functions in googlegenai.go have been marked as deprecated, encouraging the use of the more generic genkit.LookupModel and genkit.LookupEmbedder for consistency.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • go/plugins/googlegenai/actions.go
    • Added ListActions and ResolveAction methods for GoogleAI and VertexAI structs.
    • Introduced shared listActions and resolveAction helper functions to centralize action logic.
    • Implemented logic to handle different model types (Gemini, Imagen, Veo, Embedders) during action listing and resolution.
  • go/plugins/googlegenai/code_execution.go
    • Added CodeExecutionResult and ExecutableCode structs for representing code execution data.
    • Provided helper functions (newCodeExecutionResultPart, newExecutableCodePart) to create AI parts for code execution.
    • Included utility functions (ToCodeExecutionResult, ToExecutableCode, HasCodeExecution, GetExecutableCode, GetCodeExecutionResult) for extracting code execution data from AI messages.
  • go/plugins/googlegenai/embedder.go
    • Added newEmbedder function, moved from gemini.go, to create AI embedder instances.
  • go/plugins/googlegenai/gemini.go
    • Removed unused imports (encoding/json, reflect, regexp, strconv).
    • Removed toolNameRegex, BasicText, Multimodal, EmbedOptions variables/constants (moved to other files).
    • Refactored newModel to use ClassifyModel and DefaultConfig for model type-specific configuration.
    • Removed newEmbedder function (moved to embedder.go).
    • Removed toGeminiTools, toGeminiFunctionResponsePart, mergeTools, cloneToolWithoutFunctions, toGeminiSchema, resolveRef, castToStringArray, castToInt64, castToFloat64, toGeminiToolChoice, validToolName functions (moved to tools.go and schema.go).
    • Removed CodeExecutionResult, ExecutableCode, NewCodeExecutionResultPart, NewExecutableCodePart, ToCodeExecutionResult, ToExecutableCode, HasCodeExecution, GetExecutableCode, GetCodeExecutionResult types and functions (moved to code_execution.go).
    • Updated calls to NewCodeExecutionResultPart and NewExecutableCodePart to use internal new...Part functions.
  • go/plugins/googlegenai/googleai_live_test.go
    • Updated embedder usage in tests to use ai.WithEmbedderName instead of a direct embedder variable.
  • go/plugins/googlegenai/googlegenai.go
    • Removed strings and github.com/firebase/genkit/go/core imports.
    • Removed defaultGeminiOpts, defaultImagenOpts, defaultEmbedOpts variables (moved to models.go).
    • Removed ModelRef, GoogleAIModelRef, VertexAIModelRef functions (moved to refs.go).
    • Removed ListActions and ResolveAction methods from GoogleAI and VertexAI structs (moved to actions.go).
    • Marked GoogleAIModel, VertexAIModel, GoogleAIEmbedder, VertexAIEmbedder as deprecated.
  • go/plugins/googlegenai/imagen.go
    • Removed Media variable (moved to models.go).
  • go/plugins/googlegenai/model_type.go
    • Added ModelType enum for categorizing models (Unknown, Gemini, Imagen, Veo, Embedder).
    • Introduced ClassifyModel function to determine model type from its name.
    • Added ActionType, DefaultSupports, and DefaultConfig methods to ModelType for consistent property retrieval.
  • go/plugins/googlegenai/models.go
    • Moved BasicText, Multimodal, Media, and introduced VeoSupports for model capability definitions.
    • Moved defaultGeminiOpts, defaultImagenOpts, defaultVeoOpts, defaultEmbedOpts for default model options.
    • Updated supportedVideoModels to use VeoSupports and removed provider prefixes from labels.
    • Renamed googleAIEmbedderConfig to embedderConfig.
    • Added GetModelOptions and GetEmbedderOptions to retrieve options with provider-prefixed labels.
    • Refactored listModels and listGenaiModels to leverage ModelType classification.
  • go/plugins/googlegenai/refs.go
    • Added new ModelRef, GoogleAIModelRef (deprecated), VertexAIModelRef (deprecated), ImageModelRef, VideoModelRef, and EmbedderRef functions for type-safe model referencing.
  • go/plugins/googlegenai/schema.go
    • Added toGeminiSchema, resolveRef, castToStringArray, castToInt64, castToFloat64 functions, moved from gemini.go.
  • go/plugins/googlegenai/tools.go
    • Added toolNameRegex, toGeminiTools, toGeminiFunctionResponsePart, mergeTools, cloneToolWithoutFunctions, toGeminiToolChoice, validToolName functions, moved from gemini.go.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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 introduces significant refactoring and new functionality to the googlegenai plugin. Key changes include the creation of new files (actions.go, code_execution.go, embedder.go, model_type.go, refs.go, schema.go, tools.go) to better organize code related to actions, code execution, embedders, model classification, model references, JSON schema translation, and tool handling. The gemini.go file was heavily refactored, with many functions and types moved to these new files, and its newModel function updated to use a new ClassifyModel utility for determining model types and their default configurations. The googlegenai.go file was simplified by removing model and embedder option defaults, and ModelRef functions, which were moved to models.go and refs.go respectively. The models.go file now centralizes model capability definitions (BasicText, Multimodal, Media, VeoSupports) and default options, and introduces GetModelOptions and GetEmbedderOptions for consistent option retrieval. The listGenaiModels function in models.go was updated to use the new ClassifyModel for categorizing models. The googleai_live_test.go was updated to reflect the new way of referencing embedders by name. Review comments suggested improving the ClassifyModel logic to prioritize more specific model name prefixes to prevent misclassification, and refactoring the listActions function to reduce code duplication when iterating over Gemini and Imagen models. Additionally, a log.Fatal call in listGenaiModels was flagged as inappropriate for a library function and a suggestion was made to return an error instead.

Comment on lines 517 to 519
if err != nil {
log.Fatal(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

Using log.Fatal in a library function is discouraged as it terminates the entire application. This function should return the error instead, allowing the caller to decide how to handle it.

Suggested change
if err != nil {
log.Fatal(err)
}
if err != nil {
return genaiModels{}, err
}

Comment on lines +35 to +51
// Gemini models
for _, name := range models.gemini {
opts := GetModelOptions(name, provider)
model := newModel(client, name, opts)
if actionDef, ok := model.(api.Action); ok {
actions = append(actions, actionDef.Desc())
}
}

// Imagen models
for _, name := range models.imagen {
opts := GetModelOptions(name, provider)
model := newModel(client, name, opts)
if actionDef, ok := model.(api.Action); ok {
actions = append(actions, actionDef.Desc())
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The loops for appending Gemini and Imagen models are identical. You can refactor this to reduce code duplication and improve maintainability by combining them into a single loop.

Suggested change
// Gemini models
for _, name := range models.gemini {
opts := GetModelOptions(name, provider)
model := newModel(client, name, opts)
if actionDef, ok := model.(api.Action); ok {
actions = append(actions, actionDef.Desc())
}
}
// Imagen models
for _, name := range models.imagen {
opts := GetModelOptions(name, provider)
model := newModel(client, name, opts)
if actionDef, ok := model.(api.Action); ok {
actions = append(actions, actionDef.Desc())
}
}
// Gemini and Imagen models
for _, name := range append(models.gemini, models.imagen...) {
opts := GetModelOptions(name, provider)
model := newModel(client, name, opts)
if actionDef, ok := model.(api.Action); ok {
actions = append(actions, actionDef.Desc())
}
}

Comment on lines +27 to +41
func ClassifyModel(name string) ModelType {
switch {
case strings.HasPrefix(name, "veo"):
return ModelTypeVeo
case strings.HasPrefix(name, "imagen"), strings.HasPrefix(name, "image"):
return ModelTypeImagen
case strings.Contains(name, "embedding"):
// Covers: text-embedding-*, embedding-*, textembedding-*, multimodalembedding
return ModelTypeEmbedder
case strings.HasPrefix(name, "gemini"), strings.HasPrefix(name, "gemma"):
return ModelTypeGemini
default:
return ModelTypeUnknown
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The order of checks in ClassifyModel could lead to misclassification for future models. For example, a model named gemini-pro-with-embedding would be classified as ModelTypeEmbedder instead of ModelTypeGemini because strings.Contains(name, "embedding") is checked before strings.HasPrefix(name, "gemini"). It's safer to check for more specific prefixes first.

Suggested change
func ClassifyModel(name string) ModelType {
switch {
case strings.HasPrefix(name, "veo"):
return ModelTypeVeo
case strings.HasPrefix(name, "imagen"), strings.HasPrefix(name, "image"):
return ModelTypeImagen
case strings.Contains(name, "embedding"):
// Covers: text-embedding-*, embedding-*, textembedding-*, multimodalembedding
return ModelTypeEmbedder
case strings.HasPrefix(name, "gemini"), strings.HasPrefix(name, "gemma"):
return ModelTypeGemini
default:
return ModelTypeUnknown
}
}
func ClassifyModel(name string) ModelType {
switch {
case strings.HasPrefix(name, "veo"):
return ModelTypeVeo
case strings.HasPrefix(name, "imagen"), strings.HasPrefix(name, "image"):
return ModelTypeImagen
case strings.HasPrefix(name, "gemini"), strings.HasPrefix(name, "gemma"):
return ModelTypeGemini
case strings.Contains(name, "embedding"):
// Covers: text-embedding-*, embedding-*, textembedding-*, multimodalembedding
return ModelTypeEmbedder
default:
return ModelTypeUnknown
}
}

@hugoaguirre hugoaguirre changed the title Test refactor. refactor(go/plugins/googlegenai): update plugin structure Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants