Advancing AI-Driven Development: Automating code creation with Google's Gemini
Introduction
The realm of AI-driven development is constantly evolving, with each advancement opening new doors for innovation. Inspired by a blog post by Evan Seabrook work on automating pull requests using AI, I wanted to test and maybe even contribute to this concept. My goal was to learn more about AI and software development, leveraging the latest advancements in AI and software development practices.
Original Concept
The original version primarily utilized Vertex AI and GitHub's API to automate the process of handling pull requests in response to GitHub issues, if you're interested in his version here's the blog post and his repository. His implementation was a great starting point for my journey, showcasing the potential of AI in automating routine development tasks. However, I noticed opportunities for further enhancement, particularly in terms of security, flexibility, and code quality management using Google's Gemini.
My Enhancements
Infrastructure as code automation:
Working as a Cloud Engineer and with Infrastructure As Code as one of my main areas of interest, I really wanted to make the installation process as automated as possible so I decided on creating all the required resources via Terraform. This includes folder, project, cloud function deployment, and secret management in Google cloud platform.
To get started using this version simply clone the repo, cd into the infrastructure folder and run terraform apply, the code assumes you have you ssh keys at ~/.ssh/
I replaced the Vertex AI model with a more flexible approach, allowing the use of different AI models by configuring them through environment variables. This change offers greater control over the AI model selection process. I was particularly interested in using the recently released Gemini Pro model instead of vertex text generator model.
The password protection for the ssh key is enabled for enhanced security for handling GitHub private and public keys, it's now using base64 encoding and password protection, ensuring sensitive information is managed more securely.
Improved Code Generation and Branch Management:
Using Gemini introduces a more dynamic approach to generating and managing branches based on AI-driven insights, enhancing the automation's adaptability to different coding scenarios.
The code change application process has been refined, ensuring that the AI's suggestions are more accurately integrated into the existing codebase instead of replacing the existing code.
The AI bot is now optionally disabled by simply assigning the issue at creation time, the bot will only work on the issues that don't have any assignee and if the issue has already been assigned to issue is ignored.
Advanced Unit Test Adaptation:
A significant improvement in this implementation is the automated adaptation of unit tests to align with the updated code with great quality by leveraging Gemini's coding super powers. This ensures that code quality and integrity are maintained, even as changes are automatically applied.
Streamlined Pull Request Process:
The process of creating and managing pull requests was already streamlined for efficiency and transparency in the original version. here I just made a few default decisions to generate more detailed commit messages and a tighter integration with the GitHub issues they address.
Let's see it in action:
Setup the Webhook
Recommended by LinkedIn
Find a required code change in the existing code, an icon change will do
Create a Github issue and leave it unassigned, remember the title and body of the issue are instructions to the LLM
Gemini takes over, a new branch is created with the committed code
A new Pull request opens attached to the issue
The commit takes the existing code into account
Areas of improvement
Future improvements include utilizing the Langchain framework to streamline the prompt management via templates that make the code, even more versatile and easily upgradable in the future.
Another important improvement needed is figuring out the web hook logic. Currently the Github Webhook will execute correctly, but it will report a 504 timeout error because Gemini takes too long to respond. This requires creating a way to work and synchronously maybe offloading the long-running function to a secondary runner.
Conclusion
Building upon Evan Seabrook's work, I propose a few enhancements to further streamline and automate the pull request process in software development. These AI driven techniques not only save valuable developer time but also utilize the evolving capabilities of AI to handle more complex tasks, maintaining a high standard of code quality and security. This journey exemplifies the progressive collaboration between AI and human developers, paving the way for more intuitive and efficient development workflows.
By integrating advanced AI models and focusing on robust security and code quality practices, this approach marks a step forward in the realm of AI-assisted coding. It's a testament to the potential of AI in transforming software development, ensuring that as we move forward, we do so with tools that are not only powerful but also adaptable and secure.
As we continue to explore the intersection of AI and software development, it's clear that the possibilities are boundless. With each improvement and innovation, we're not just automating tasks; we're reshaping the future of how software is developed and maintained.
Thanks for exploring this further, Joseph! It's an interesting area to explore. I see that more safeguards were needed with Gemini (explicitly removing markdown from response text), which was my experience as well; hopefully instructions to exclude markdown in the response is more heavily weighted in future versions of the model!