This paper examines the early adoption of Amazon Q Developer Code Customization by Infosys, highlighting the potential of AI-driven, customized code generation in enterprise software development. Amazon Q Developer Code Customization allows organizations to fine-tune AI models to their specific codebases and domain knowledge, enhancing developer productivity and code quality.
The study details Infosys' experience in building a custom model using their proprietary AI solution's codebase, primarily consisting of Java applications with Spring Boot and MVC frameworks, alongside Python projects. It outlines the model building process, integration with development environments, and presents a series of best practices and tips in evaluating the custom model's performance in various coding scenarios.
This article discusses Amazon Q Developer and its Code Customization capability. Amazon Q Developer is a powerful machine learning service that provides code generation and assistance to developers. Its capabilities include offering code suggestions, autocompletions, and generating code snippets based on natural language prompts.
The article primarily focuses on Amazon Q Developer Code Customization:
Amazon Q Developer can be customized to generate more relevant recommendations by making it aware of internal libraries, APIs, best practices, and architectural patterns. By creating a customization, customers combine the power of the general models with the organizational value of their own code. Currently, Amazon Q Developer customizations are available on code bases written in Java, JavaScript, TypeScript, and Python. Files written in other languages supported by Amazon Q Developer (C#, Go, Rust, PHP, Ruby, Kotlin, C, C++, Shell scripting, SQL, and Scala) will not be used when creating the customization or when providing customized recommendations in the IDE based on the internal code repositories.
An Infosys’ developed inhouse solution uses AI to extract, understand, and provide insights and recommendations on vast amount of data collected by customer care centers. This inhouse solution platform helps enterprises deliver superior experiences to both customers as well as employees. In addition, it reimagines contact center operations for a smooth customer journey, primarily consisting of Java applications including Spring Boot and MVC frameworks as well as a few Python projects.
Over time the codebase became increasingly sophisticated, incorporating advanced AI algorithms, data processing pipelines, and intricate business logic specific to customer care operations. While this complexity was necessary to deliver powerful features, it presented challenges for our development team.
Experienced developers found themselves dedicating significant time to adding new features and enhancing existing services. They often had to navigate through multiple interconnected modules and consider various edge cases specific to different customer scenarios. This process, while manageable for veterans familiar with the system, was time-consuming and sometimes led to bottlenecks in feature delivery.
The situation was even more challenging for new developers. Despite their technical skills, these newcomers struggled to quickly grasp the full context of the codebase. This learning period often resulted in slower onboarding and delayed productivity.
The promise of an AI-powered coding assistant that could be tailored to understand our specific codebase and domain knowledge immediately became apparent.
We saw the potential for Amazon Q Developer Code Customizations to serve as a knowledgeable guide for our developers, helping them navigate our complex AI solution more efficiently. For experienced team members, we envisioned it as a tool to accelerate feature development and reduce the time spent on repetitive coding tasks. For new employees, Amazon Q Developer would act as an always-available mentor, providing context-aware suggestions and helping them understand the intricacies of our platform more quickly.
To customize Amazon Q Developer, the code base has to be ingested. The size of the code repositories was around 80 MB which is over the recommendation of 20 MB minimum.
To create a customization, subscription to Q Code Customization professional tier is a prerequisite. The Q Code Customization administrator must be attached to an IAM role that allows customizations. It has a customer managed policy that allows customizations and is available on AWS documentation.
Figure 1: Steps of creating customization
Our inhouse solution repositories were on a different platform and to ingest this repository we downloaded the code to a nS3 bucket and used the S3 location option as our repository connection.
A few common errors while building the model: insufficient code, code size exceeds the allowed limit of 500 MB, duplicate files, files in unsupported format, or an unsupported programming language file.
Creating the customization can take few hours depending on the size of repository. For this inhouse solution it took about an hour.
Once the customization is built there is an evaluation score that gets generated. This score indicates Amazon Q Developer Code Customization's evaluation of how effective the customization is.
For receiving a higher score, options are adding more repositories with diverse programming languages, remove auto-generated files, ensuring that there are at least 10 files with the same programming language.
We used Visual Studio Code editor to test the customization. After installing AWS tool kit and enabling IAM Identity Center authentication, the custom model will automatically be visible which can be enabled in the command palette as shown below.
Figure 2: Visual Studio Code control palette
And we are all set to use the customization and get the recommendations. Up-to 5 customizations are allowed.
We tested the code generation with various factors like productivity improvements, code quality and consistency and scalability and collaboration. We also tested on how custom model generated code is different from the professional tier of the service.
To maximize the benefits of Amazon Q Developer Code Customization and overcome common challenges, we've compiled a set of tips based on our extensive testing. These tips cover various aspects of development, from productivity improvements to code quality and consistency.
Once in the IDE, when starting to code or writing a comment, immediately the context is understood and the service starts generating which is a notable feature.
Figure 3: Q in action
Tip 1: Leverage Context-Aware Code Generation
Challenge: Starting a new coding task in a complex project.
With the default model – the existing function in the codebase and its arguments are not used correctly.
Figure 4: Default model code generation
Using Q customization: Begin by writing a brief comment describing the intention. Q Developer immediately understands the context and starts generating relevant code, giving a head start.
Here it understood the existing function and its required arguments.
Figure 5: Q in action
Tip 2: Enhancing Existing Functionality
Challenge: Modifying existing project files to add new features.
Default Q Developer output
Figure 6: Default model code generation
Using Q Customization: Clearly describe the new functionality that has to be added in a comment. Q Developer will suggest code that integrates seamlessly with existing codebase.
The generated code used the existing function, its arguments.
Figure 7: Q code generation
Tip 3: Adapting Functions for New Requirements
Challenge: Modifying existing functions to accept new arguments or handle additional logic.
No recommendation was suggested by the default model.
Using Q customization: Write a comment explaining the new parameters or logic to be incorporated. Q Developer will provide suggestions on how to modify the function while maintaining its original purpose.
In the generated code the getAuthUserDomain is identified correctly
Figure 8: Q code generation
Tip 4: Improving Error Handling
Challenge: Adding comprehensive error logging to code.
Using Q Customization: Ask Q Developer to "add error logging to this function". It will suggest appropriate try-catch blocks and logging statements based on project's existing error handling patterns.
Example where for a new function a method that was not present was generated. This had to be resolved by first creating the variable and its getter and setter methods.
Figure 9: Q code generation
Tip 5: Implementing Complex Conditions
Challenge: Adding intricate conditional logic to code.
Using Q Customization: Describe the conditions in natural language. Q Developer can help translate these into efficient if-else statements or switch cases.
Figure 10: Q code generation
Created DTO class:
Figure 11: Q code generation
Tip 6: Cross-File Function and Variable Usage
Challenge: Ensuring correct usage of functions and variables from other files.
Using Q Customization: When referencing external components, include the file name in the comment. For example, "use the processData function from DataHandler.java". Q Developer will provide accurate suggestions with proper imports.
But one factor to remember is that code does not get generated across different relevant files in the IDE even when they are kept open.
Code gets generated in one file only where its prompted. In the other files we have to provide the relevant prompts to generate the corresponding code snippets.
Below screen print shows that even if all files are kept open in IDE, the generated code is with errors and no other file is modified, example below
Figure 12: Q code generation
Prompted another file to create the corresponding method
Figure 13: Q code generation
Regenerated the function now without errors:
Figure 14: Q code generation
Tip 7: Security Vulnerability Checks
Challenge: Identifying potential security issues in the code.
Using Q Customization: After generating code, ask Q Developer to "review this code for security vulnerabilities". It can highlight potential issues and suggest more secure alternatives.
We ran a security scan and it identified the missing imports
Figure 15: Q code generation
Here are a few observations and insights based on our findings while testing Amazon Q Developer Code Customization
While it demonstrates an understanding of code context and project structure, there are areas for improvement, such as better import generation, support for external SDKs and data formats, and handling interdependencies across multiple files. Additionally, developers should be prepared to review and refine the generated code, as Q Code Customization may introduce syntax errors or produce incomplete solutions, especially in more complex scenarios.
The below table represents the test outcome.
Test Case | Results | Met Expectations % |
---|---|---|
New function creation referencing an argument from another existing function | Scanned the existing code correctly and used the arguments correctly | 100 |
Creation of another function to check the domain used | A domain selection function is correctly referenced and new function is generated with accuracy | 100 |
Creation of a new function with a new method | Function with the new method was generated, but there was syntax errors as the variable was not defined, needed human intervention to correct these | 75 |
Creation of a new function that requires changes in other files as well | Even if the other files are open in the IDE, code gets generated in one file only where its prompted. In the other files we have to provide the relevant prompts to generate the corresponding code snippets. | 20 |
Test for connecting to external SDKs | Not supported | 0 |
Change the functionality of existing code | Excellent code generation understanding the context and the code base | 100 |
Test how well the custom model is able to understand the existing code | Excellent code generation understanding the context and the code base | 100 |
Test the generation of new imports as well along with code changes | Imports are not getting generated or sometimes not all imports are recommended | 50 |
Missing imports check | Security scan identifies the missing imports correctly | 100 |
Cloud Formation template generation | Unable to test | NA |
The below table lists the potential benefits:
Personas | Count | Productivity Gain % |
---|---|---|
Trainee | 3 | > 35 |
Experienced Developer | 4 | 20 to 40 |
Lead/Manager | 1 | > 15 |
Overall | 6 | Average ~ 30 |
With its customization capabilities, Q Code Customization's custom model empowers organizations to leverage the full potential of AI-assisted coding while aligning it with their unique requirements and software development practices. As a result, organizations can accelerate their digital transformation initiatives, drive innovation, and deliver high-quality software products more efficiently.
To keep yourself updated on the latest technology and industry trends subscribe to the Infosys Knowledge Institute's publications
Count me in!