Code Generation API, With Generative Models

What is Code Generation and Why Use Generative AI?

Code generation is about creating source code, in a specific programming language, from simple human instructions. For example, a human can ask an AI to create a blue button in HTML, and the AI will return the proper HTML code for that.

Example: do you want to help your employees request the database while they know nothing about SQL? Thanks to code generation, they can now simply ask what they want in human language. Let's say you want to ask the following: Fetch three employees from the Employee table. The AI model will return the following:

SELECT * FROM Employee ORDER BY last_name DESC LIMIT 3;

The above examples are simple examples but it is possible to perform much more complex code generation thanks to generative models.

LLaMA 2, Dolphin, and ChatDolphin are the most advanced alternatives to GPT-4, ChatGPT, and Codex. These models are so big that they can adapt to many situations, and perfectly sounds like a human. For advanced use cases, it is possible to fine-tune Dolphin (train them with your own data), which is a great way to get a code generation application that is perfectly tailored to your company/product/industry.

Source code generation

Why Use Code Generation?

Programming is at the heart of many things today, but few people know how to code. Besides, developers themselves are constantly looking for ways to improve their productivity. Here are a couple of examples on how code generation can help:

Database Querying

Most of the valuable data is located in relational databases today, but few people know how to use SQL to get the results they want. Simply ask AI the SQL query you want to perform and it will generate it for you.

Mock Up Creation

Creating a quick mock-up with HTML and CSS is now much easier thanks to code generation. Anyone from a marketing department is able to create such a mock-up thanks to AI.

Focus on Complex Logic Only

Developers often spend time writing repetitive code that does not involve too much complex logic. This part of their work can now be offloaded to AI.

Speed Up Tests Creation

Writing unit tests and integration tests is a pain, but it's critical to the quality of an application. It is now possible to let AI write the tests for you so you can focus on something more important.

Performing Code Generation with Generative Models

Building an inference API for code generation based on generative models is a necessary step as soon a you want to use code generation in production. But building such an API is hard... First because you need to code the API (easy part) but also because you need to build a highly available, fast, and scalable infrastructure to serve your models behind the hood (hardest part). It is especially hard for machine learning models as they consume a lot of resources (memory, disk space, CPU, GPU...).

Such an API is interesting because it is completely decoupled from the rest of your stack (microservice architecture), so you can easily scale it independently, and you can access it using any programming language. Most machine learning frameworks are developed in Python, but it's likely that you want to access them from other languages like Javascript, Go, Ruby...

NLP Cloud's Code Generation API

NLP Cloud proposes a code generation API based on GPT that gives you the opportunity to perform code generation out of the box, with breathtaking results. If the base generative model is not enough, you can also fine-tune/train your own generative model on NLP Cloud and automatically deploy the new model to production with only one click.

For more details, see our documentation about code generation with generative models here. For advanced usage, see the text generation API endpoint here. And easily test code generation on our playground.