feat: add genai-migrate codemod CLI for legacy google-generativeai#2748
Open
jeshiomurmu wants to merge 2 commits into
Open
feat: add genai-migrate codemod CLI for legacy google-generativeai#2748jeshiomurmu wants to merge 2 commits into
jeshiomurmu wants to merge 2 commits into
Conversation
Adds a formatting-preserving source-to-source rewriter (powered by libcst) to help developers migrate from the deprecated google-generativeai patterns to the new google-genai Client/Models/Chats architecture. Addresses the DX crisis outlined in upstream issue googleapis#1606 where AI code generators hallucinate legacy patterns (GenerativeModel, start_chat, genai.configure), costing developers weeks of debugging. Supported transforms: - import google.generativeai as genai -> from google import genai - genai.configure(api_key=...) -> client = genai.Client(api_key=...) - genai.GenerativeModel('gemini-X') -> model name captured as string - model.generate_content(...) -> client.models.generate_content(model=..., contents=...) - model.generate_content(..., stream=True) -> client.models.generate_content_stream(...) - model.start_chat(history=...) -> client.chats.create(model=..., ...) - model.count_tokens(...) -> client.models.count_tokens(model=..., contents=...) Install: pip install google-genai[migrate] Usage: genai-migrate ./app/ --diff # preview genai-migrate ./app/ --in-place
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a source-to-source migration tool (
genai-migrate) powered by LibCST to automate the transition from the deprecatedgoogle-generativeaipackage to the newgoogle-genaiSDK.Why this is needed
Developers are currently facing a 'DX crisis' (referenced in issue #1606) where AI code generators continue to hallucinate legacy patterns. Manually migrating large codebases is error-prone and time-consuming. This tool automates the most common pattern shifts while preserving original code formatting.
Supported Transformations
import google.generativeai as genai->from google import genaigenai.configure()->genai.Client()GenerativeModelvariables to map them to the new Client architecture.model.generate_content()->client.models.generate_content()stream=Truecalls togenerate_content_stream().start_chat()andcount_tokens()to the newclient.chatsandclient.modelsnamespaces.Quality Assurance
Fixes #1606