This is a Visual Studio Code extension for ChatGPT that was built using only ChatGPT and 5 beers.
The README.md file for this extension was generated by ChatGPT.
ChatGPT: Query (will provide a prompt for you to ask a question)
ChatGPT: Add tests (generates tests based on file/text selection)
ChatGPT: Why is my code broken? (analyses your code to highlight any logic/syntax errors)
ChatGPT: Explain code
ChatGPT: Refactor
ChatGPT: Reset token (clears access & clearance tokens if expired or having issues)
Everything except Reset Token and Query are available from the context menu when right-clicking in the editor.
Usage
To use the extension:
This package requires a valid session token from ChatGPT to access it's unofficial REST API.
Open the VS Code Command Palette and Type ChatGPT: Reset token, this will prompt you for your session token and as of 12/12/2022 you also need a clearance token.
To get the tokens:
Go to https://chat.openai.com/chat and log in or sign up (preferably in a browser other then Chrome, see below).
Open dev tools.
Open Application > Cookies (Storage > Cookies on FireFox)
Copy the value for __Secure-next-auth.session-token & cl_clearance and enter it into the prompt from ChatGPT: Reset token
Go to the Network tab and select any request.
Copy the value for user-agent from the Request Headers and enter it into the prompt.
Once you're logged in, you can ask ChatGPT any question and supply source code from your current file/selection.
Because of cloudflare, there are now several limitations, see here for more.
There are currently users who have issues even when following all of the above (see this comment). If you're using Chrome to obtain the tokens, try using a different browser (e.g. Brave), as it seems like using Chrome is often the cause of this.
Support
If you need help using this extension, please open an issue on the GitHub repository for this extension.
Credits
ChatGPT - The large language model trained by OpenAI that was used to generate this README file
chatgpt-api - The NPM package used to query ChatGPT
mpociot's extension - Inspiration for the project and the original webview panel