ChatGPT: AI Programming Assistant
Overview
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.
Key Bindings and Commands
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.
Prompt Areas
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
Configuration
API Key
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.
Graphical Help
1. Generate Code
Generate code using the GPT Code Assistant by pressing Ctrl+Alt+G
.
2. Chat with GPT
Chat with GPT using the command Ctrl+Alt+C
for real-time assistance.
Usage
- 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.
Usage Instructions
Select the Code Snippet You Want to Work With
Use the Command Palette or Assigned Shortcut Keys
- Example 1: Open the Command Palette by pressing
Ctrl+Shift+P
, then type ChatGPT: AI Programming Assistant
to see the available commands. Choose Optimize 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.
Additional Examples
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- OpenAI for providing the API.
- Visual Studio Code for an excellent code editor.
Welcome Message
Thank you for using ChatGPT: AI Programming Assistant! We hope this tool enhances your coding experience and boosts your productivity. Happy coding!