Generative AI for Code: what you need to know in 2023

ChatGPT has sparked various conversations across the AI industry on the emerging role and capabilities of generative AI. There are many questions being raised: How accurate are the results produced by generative AI? Will these tools replace humans? What are the ethical implications of using AI to generate content? Since generative AI is still in its primitive stages, it is difficult to give definitive answers to most of these questions.

However, in a short span of time, generative AI tools have produced impressive outputs, which is indicative of promising results in the future. In this article, we scope out the generative AI landscape and particularly look at the role of generative AI in the software and coding space.

What is generative AI?

Machine learning and artificial intelligence have conventionally been used for analytical tasks. That is, algorithms process data and provide analytical insights, often at a volume and efficiency that cannot be achieved by humans.

In the case of generative AI, algorithms use data to generate new and unique content such as text, images, videos, and code (hence the name generative AI).

Key applications of generative AI

The application space of generative AI is large. This spans from creative industries to fields such as banking and healthcare. Generative AI offers a range of benefits to these industries, among which, increased accuracy and efficiency of predictions take priority.

The types of tasks that generative AI can achieve in different application spaces are also rather varied. These include activities such as text generation and the creation of audio and video material. Figure 1 below summarises the various application layers of AI, along various pillars.

Figure 1: Applications of generative AI, originally published in: https://www.sequoiacap.com/article/generative-ai-a-creative-new-world/

In the software space, the application of generative AI for code is a valuable application scenario to further explore. We delve into this below:

Using AI to generate production-ready code

In software development, generative AI can be used to write and improve code bases, ultimately enhancing the quality and efficiency of applications. There is a variety of tools that contribute to different parts of the code development pipeline. In Figure 2 below, we categorise these tools based on three functions:

  1. Code generation (tools that take natural language input and convert it to code)
  2. Code completion (tools that complete sections of code once provided with a prompt)
  3. Code review (tools that test code for quality, to ensure that code efficiently does what it is expected to do)

While tools that produce and test code have the potential to bring about significant change to the coding landscape, we also identify the value of optimisation to make the best out of generative tools. With optimisation, the outputs produced by generative tools can be made to perform faster and at a lower cost, bringing about the most profitable outcomes for businesses. We visualise the placement of optimisation tools in the generative AI in Figure 2 below.

Figure 2: Generative AI tools in the code landscape can lead to faster and more efficient applications

Code generation

As AI grows in complexity, so does the underlying code. Organisations are looking for ways to code more efficiently, saving developer time and computational resources. A significant contribution made by generative AI to ease the process of coding is to convert natural language prompts to code. While code generation makes coding more efficient for developers, it also opens up the coding space for those without much formal training or background. Ideally, anyone with an interest in developing a program is able to provide natural language commands to have these tools generate relevant code.

Figure 3 gives an example of code generation from natural language prompts.

Figure 3: Generating code from natural language prompts using OpenAI ChatGPT, available at: https://chat.openai.com/chat

Code completion

During the process of writing code, developers are able to use AI-based tools to have suggestions for the code they write. These tools use natural language processing to analyse code, suggest relevant code snippets or keywords, and complete partial code with the full, syntactically correct language. Generative AI tools for code completion are becoming increasingly popular among developers, as they reduce the time and effort required to write complex code.

A survey by GitHub Copilot shows that using GitHub Copilot brings about significant increases in developer productivity when measured along three pillars:

Figure 4: Survey on developer productivity when using GitHub Copilot, available at: https://github.blog/2022-09-07-research-quantifying-github-copilots-impact-on-developer-productivity-and-happiness/

Often, code completion platforms offer an extension to be integrated into a developer’s coding environment, allowing for seamless integration of generative AI into the coding workflow.

GitHub Copilot is a good example of a generative AI-based code completion tool.

Figure 5: Example of code completion from GitHub Copilot

Code review

Assessing code for bugs and inefficiencies is as important as developing code. As a result, code reviews are a critical part of the software development process, and can be done manually or with assistive tools. AI-powered tools elevate the conventional code review process with better insights and greater efficiency.

Amazon CodeGuru is a generative AI-based tool that can be used for code review.

AI-generated code requires optimisation to meet production-quality

While code generation, completion, and review technologies are progressing rapidly, they are still not where we want them to be. In order for code to be production-quality, they are expected to display some essential characteristics:

Reliability: Code does what it is supposed to do, without any major failures.

Clarity and consistency: Code is clear to read and understand, and follows consistent stylistics and standards.

Robust: Code is able to handle a variety of different application scenarios, including those that occur less commonly.

Efficient: Code is productive, and wastes minimum time, energy, and resources.

In the current generative AI landscape, code produced by generative tools is often far from ideal and does not meet these quality criteria. Code created by generative AI tools can even be faulty. For instance, StackOverflow temporarily banned answers generated by ChatGPT to be posted on the site, since it could flood the site with answers that may seem true at the surface level, but are incorrect. This highlights the value and the need for additional tools that can establish the quality of code bases produced using generative technologies.

In layperson’s terms:

Many modern-day devices/writing applications provide a text autocomplete function. However, rarely do we share an autocompleted text (an email, a text message etc.) without checking for accuracy.

Code created with generative AI is similar; they make the development process faster, but we cannot deploy generated code without quality checks.

Code optimisation

Code optimisation has long been a pain point for developers, where retrieving and improving underperforming code is a cumbersome and inefficient process. Even the most experienced engineers will spend days finding out the best ways to optimise code. Due to these complexities, optimising code can easily be left out of the development process. While generative AI makes the code creation process easier, the need for optimisation remains strong.

Optimisation is particularly required to ensure that code bases save time and costs when they are executed. Generative AI itself can be used to optimise code more efficiently, and with minimal input from developers.

Using AI to power code optimisation

With over 10 years of research experience, TurinTech has developed Artemis AI, a signature platform that utilises proprietary research as well as generative AI for optimisation. Artemis AI is the only technology of its kind, making the platform a pioneer in the AI industry.

Artemis AI works on users’ code bases to automatically detect and reduce inefficiencies. Artemis AI can conduct static analysis of code, where code is examined to identify and execute improvements, and dynamic analysis of code, where codebases are improved via scanning code while they run.

Artemis AI uses proprietary pre-trained language models for code optimisation. These models get better with time and with each optimisation. Powered by genetic algorithms and inspired by the theories of natural evolution, Artemis AI also encapsulates multi-objective optimisation for code optimisation. The results generated are validated to ensure accuracy and efficiency.

By combining Artemis AI technology with other generative AI tools, developers can make massive time and cost savings, while also improving the quality of applications.

TurinTech’s cutting-edge code optimisation tool simplifies and streamlines the process of optimising code by integrating it within your CI/CD pipeline with three easy steps:

Figure 6: Artemis AI streamlines the code optimisation process into three easy steps

Step 1: Create a pull request

The developer creates a pull request with code changes that they wish to merge to a code base as shown in Figure 7.

Figure 7: Create a pull request to start the optimisation process

Step 2: Automated execution of Artemis AI code optimiser

Artemis AI code optimiser automatically runs on pull requests and suggests developers changes to lines of code that can bring about boosts to the efficiency of the code base. Artemis AI metrics quantify the gains in runtime, CPU usage, and memory, so that developers can make informed decisions about improvements to efficiency that can be expected.

Figure 8: Artemis AI optimisation summary

Step 3: Apply suggestions and merge changes

At the end of the optimisation process, Artemis AI provides changes to lines of code that developers can apply to their code bases. Figure 9 gives a sample set of Artemis AI suggestions.

Figure 9: evoML suggestions for optimisation

Ethical, legal, and regulatory concerns

As impressive as its results are, generative AI is a double-edged sword. On the plus side, generative AI brings unimaginable boosts to the productivity and accuracy of activities across a variety of industries. However, on the downside, generative AI comes with a string of ethical, legal, and regulatory concerns.

In the software space, one of the biggest concerns of generative AI-based software development is the difficulty for AI-generated code bases to pass regulatory checks. This is specifically the case for AI-based software tools used in the financial industry, where regulation of systems is crucial to ensure unbiased decision-making. For instance, in use cases such as credit scoring and loan-related decision-making, a high level of precision is required to ensure that individuals are not being unfairly treated based on real-world biases found in data. Financial institutions are often required to convince regulatory bodies of the credibility of their systems, which can be difficult when generative AI is used to develop software tools.

Another ethical concern about using generative technologies is the copyright issues that arise with content generated using generative tools. For instance, GitHub Copilot is facing legal challenges on the basis that it violates copyrights. This emphasises the need for organisations to be well aware of the content produced by generative AI tools, as well as the implications they can have on socio-economic spheres.

Contrary to other tools, Artemis AI uses training data available under open licenses, allowing users greater freedom and protection in using generative technologies in their code bases.

Unlock the Full Potential of Your Code with GenAI.

Contact Us

© 2024 · TurinTech AI. All rights reserved.

This is a staging enviroment