ChatGPT: AI Programming Assistant is a powerful VS Code extension leveraging OpenAI’s models for AI-driven code generation, optimization, debugging, unit test creation, and interactive tutorials, complete with a cheat sheet of 500 programming prompts.
The following commands have been assigned shortcut keys for better productivity:
- Generate Code:
Ctrl+Alt+G
- Generates code based on the selected text.
- Generate Unit Test:
Ctrl+Alt+U
- Generates a unit test for the selected code.
- Optimize Code:
Ctrl+Alt+O
- Optimizes the selected code.
- Debug Code with AI:
Ctrl+Alt+D
- Debugs the selected code with AI assistance.
- Explain Code Differences:
Ctrl+Alt+E
- Explains the difference between two code snippets.
- Chat with GPT:
Ctrl+Alt+C
- Chat directly with GPT for interactive Q&A or coding help.
- Interactive Learning Mode:
Ctrl+Alt+L
- Provides tutorials on various coding topics based on user input.
You can customize these key bindings in the keybindings.json
file in VS Code.
The extension includes a total of 500 prompt examples across the following:
- 100 Python Prompts:
pyprompts
- 100 HTML Prompts:
htmlPrompts
- 100 JavaScript Prompts:
jsprompts
- 100 CSS Prompts:
cssPrompts
- 100 Other Languages Prompts:
otherPrompts
To use the OpenAI features, you need to set your OpenAI API key in the extension settings:
- Open the Command Palette (Ctrl+Shift+P) in Visual Studio Code.
- Search for and select Preferences: Open Settings (JSON).
- Add the following lines to your settings:
"gptCodeAssistant.openaiApiKey": "YOUR_OPENAI_API_KEY", // Replace YOUR_OPENAI_API_KEY with your actual OpenAI API key.
"gptCodeAssistant.maxTokens": 300, // Adjust the maximum number of tokens
"gptCodeAssistant.model": "gpt-4" // Choose the GPT model (e.g., gpt-3.5-turbo,gpt-3.5-turbo-16k, gpt-4, gpt-4-32k)
These settings allow you to customize the GPT model used and the maximum number of tokens for each response.
Generate code using the GPT Code Assistant by pressing Ctrl+Alt+G
.
Chat with GPT using the command Ctrl+Alt+C
for real-time assistance.
- Select the code snippet you want to work with.
- Use the command palette (
Ctrl+Shift+P
) or the assigned shortcut keys to run any ChatGPT: AI Programming Assistant command.
-
Select the Code Snippet You Want to Work With
- Example: Highlight a function in your code that you want to optimize. For instance, if you have the following JavaScript function:
function add(a, b) { return a + b; }
- Example: Highlight a function in your code that you want to optimize. For instance, if you have the following JavaScript function:
-
Use the Command Palette or Assigned Shortcut Keys
- Example 1: Open the Command Palette by pressing
Ctrl+Shift+P
, then typeChatGPT: AI Programming Assistant
to see the available commands. ChooseOptimize Code
to enhance the selected function. - Example 2: Alternatively, use the assigned shortcut key for the command. For instance, if you want to generate a unit test for the selected code, simply press
Ctrl+Alt+U
after highlighting your function.
- Example 1: Open the Command Palette by pressing
-
Select Code for Debugging:
- Highlight a piece of code you suspect contains an error. For example:
def divide(x, y): return x / y
- Press
Ctrl+Alt+D
to use the AI to debug the highlighted code.
- Highlight a piece of code you suspect contains an error. For example:
-
Generate Code from Comments:
- If you have a comment describing what you want to implement, such as
// Create a function to calculate the factorial
, select that comment. - Then use
Ctrl+Alt+C
to generate the corresponding code.
- If you have a comment describing what you want to implement, such as
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenAI for providing the API.
- Visual Studio Code for an excellent code editor.
Thank you for using ChatGPT: AI Programming Assistant! We hope this tool enhances your coding experience and boosts your productivity. Happy coding!