CodeGPT: ChatGPT inside vscode
Can you imagine having an intelligent assistant that helps you write code, solve problems, optimize your work, and learn new skills? Well, that's what CodeGPT offers.
It's an extension for Visual Studio Code that allows you to use the official OpenAI API to integrate GPT-3.5 or GPT-4 (as well as other models) into the code editor.
What is CodeGPT?
CodeGPT is an extension for VSCode that provides instant explanations for your code within the editor using AI.
CodeGPT can leverage any of the GPT (Generative Pre-trained Transformer) models, which are capable of generating text based on input, whether it's a word, a phrase, or a context.
In addition to OpenAI's text generation models, you can also use one of the following models for code generation:
- Google MakerSuite
- Microsoft Azure
- Anthropic
- Cohere
- AI21
- Huggingface
- GPT4All
- Ollama
Installation and Configuration of CodeGPT
To set up CodeGPT in VSCode, follow these steps:
1. Open VSCode and select the "Extensions" option in the left menu.
2. Search for "Code GPT" in the search bar and select the option to install the extension.
3. Once the extension is installed, open the "Settings" menu in VSCode.
4. Look for the "Extensions" option and select CodeGPT.
5. Now, to add your OpenAI API key, press cmd+shift+p and search for the term 'CodeGPT: Set API KEY.' You can generate your OpenAI keys here.
6. Enter your OpenAI API key in the input field and press enter.
With this, you would have the extension ready to use. You can customize the language, the desired response format, the maximum number of tokens to use for each response, the language model, and the temperature in the configuration.
Key Features of CodeGPT
Among the main features of CodeGPT are:
Chat Usage within VSCode
The extension provides integration of ChatGPT within VSCode, allowing you to interact with it by requesting code or asking about code in your project.
Generate Code:
You can write a comment requesting code and then press "cmd+shift+i" for the extension to open a space with the generated code, for example:
// Generate a regex to validate a hexadecimal colorlet regex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
Explain Code
You can also ask CodeGPT to explain code. To do this, select the desired code and right-click.
In the popup menu, select the "Explain CodeGPT" option, and it will open a new window with a detailed explanation of the selected code.
Refactor Code
CodeGPT allows you to refactor code. Highlight the code snippet, right-click, and in the popup menu, select the "Refactor CodeGPT" option. CodeGPT will open a new window with the refactored code.
Document Code
Select the desired code, right-click, and in the popup menu, choose the "Document CodeGPT" option. CodeGPT will open a new window with the documentation for the selected code.
Find Problems in Code
Select the desired code, right-click, and in the menu, choose the "Find Problems CodeGPT" option. CodeGPT will search for and display any problems found in a new window.
Generate Unit Tests
To do this, select the desired code, right-click, and select the "Unit Test CodeGPT" option. A new window will appear with the code for conducting tests.
Simulate Code Compilation
Select the desired code, right-click, and choose the "Compile & Run CodeGPT" option, and CodeGPT will simulate being a compiler, executing the code.
Advantages and Disadvantages of CodeGPT
Advantages of CodeGPT include:
- Ability to generate high-quality and consistent code.
- User-friendly and customizable.
- Wide variety of useful features for developers.
Disadvantages of CodeGPT include:
- Dependency on an internet connection to use the OpenAI API.
- Possible additional cost to use the OpenAI API based on usage and the number of requests made.
- Limited accuracy for more complex code problems.
CodeGPT Demo Video
In this video, Daniel, the extension developer, demonstrates each of the functionalities and how to use CodeGPT:
CodeGPT, the AI Co-pilot that Makes Your Life Easier
This extension is easy to install and use, providing you with a unique and personalized programming experience. If you want to learn more about CodeGPT, you can do so from here.
If you enjoyed this article, feel free to share it with your friends and fellow programmers. Until next time!