GithubHelp home page GithubHelp logo

chatgpt-vscode's Introduction

ChatGPT and GPT4 extension for VSCode

Visual Studio Marketplace Version Visual Studio Marketplace Rating (Stars) Visual Studio Marketplace Downloads Github stars

This Visual Studio Code extension allows you to use the ChatGPT API to generate code or natural language responses from OpenAI's ChatGPT or GPT4 to your questions, right within the editor.

Supercharge your coding with AI-powered assistance! Automatically write new code from scratch, ask questions, get explanations, refactor code, find bugs and more ๐Ÿš€โœจ

Links:


Refactoring selected code using chatGPT

Features

  • ๐Ÿ’ก Ask general questions or use code snippets from the editor to query ChatGPT via an input box in the sidebar
  • ๐Ÿ–ฑ๏ธ Right click on a code selection and run one of the context menu shortcuts
    • automatically write documentation for your code
    • explain the selected code
    • refactor or optimize it
    • find problems with it
  • ๐Ÿ’ป View ChatGPT's responses in a panel next to the editor
  • ๐Ÿš€ See the response as it is being generated in real time
  • ๐Ÿ’ฌ Ask follow-up questions to the response (conversation context is maintained)
  • ๐Ÿ“ Insert code snippets from the AI's response into the active editor by clicking on them

Setup

To use this extension, install it from the VSCode marketplace.

  1. After the installation is complete, you will need to add your OpenAI API key to the extension settings in VSCode. To do this, open the Settings panel by going to the File menu and selecting Preferences, then Settings.
  2. In the search bar, type ChatGPT to filter the settings list.
  3. In the ChatGPT section, enter your API key in the top field

After completing these steps, the extension should be ready to use.

Building from source (not applicable for VSCode marketplace version)

To build the extension from source, clone the repository and run npm install to install the dependencies. You have to change some code in chatgpt module because VSCode runtime does not support fetch. Open node_modules/chatgpt/dist/index.js and add the following code at the top of the file:

import fetch from 'node-fetch'

Then remove the following lines (around line 20):

// src/fetch.ts
var fetch = globalThis.fetch;

You also need to replace the following part near the top of the file:

// src/tokenizer.ts
import { encoding_for_model } from "@dqbd/tiktoken";
var tokenizer = encoding_for_model("text-davinci-003");
function encode(input) {
  return tokenizer.encode(input);
}

with

// src/tokenizer.ts
import GPT3TokenizerImport from "gpt3-tokenizer";
var GPT3Tokenizer = typeof GPT3TokenizerImport === "function" ? GPT3TokenizerImport : GPT3TokenizerImport.default;
var tokenizer = new GPT3Tokenizer({ type: "gpt3" });
function encode(input) {
  return tokenizer.encode(input).bpe;
}

due to the fact that the @dqbd/tiktoken module is causing problems with the VSCode runtime. Delete node_modules/@dqbd/tiktoken directory as well. If you know how to fix this, please let me know.

In file node_modules/chatgpt/build/index.d.ts, change line 1 to

import * as Keyv from 'keyv';

and line 4 to

type FetchFn = any;

Obtaining API key

To use this extension, you will need an API key from OpenAI. To obtain one, follow these steps:

  1. Go to OpenAI's website. If you don't have an account, you will need to create one or sign up using your Google or Microsoft account.
  2. Click on the Create new secret key button.
  3. Copy the key and paste it into the API Key field in the extension settings.

Settings

The extension can be configured or customized by changing several settings. You can choose between ChatGPT and GPT4 by changing the Model setting (only if you already have access to GPT4 API). A custom API URL can also be set in the API URL field (probably looks something like https://openai.xxxxxx.net/v1, can be used to connect to a self-hosted instance of the API or a proxy).

Using the Extension

To use the extension, open a text editor in Visual Studio Code and open the ChatGPT panel by clicking on the ChatGPT icon in the sidebar. This will open a panel with an input field where you can enter your prompt or question. By clicking enter, it will be sent to ChatGPT. Its response will be displayed below the input field in the sidebar (note that it may take some time for it to be calculated).

Writing new code using chatGPT

You can also select a code snippet in the editor and then enter a prompt in the side panel, or right-click and select "Ask ChatGPT". The selected code will be automatically appended to your query when it is sent to the AI. This can be useful for generating code snippets or getting explanations for specific pieces of code.

Refactoring selected code using chatGPT

To insert a code snippet from the AI's response into the editor, simply click on the code block in the panel. The code will be automatically inserted at the cursor position in the active editor.

chatGPT explaining selected code

You can select some code in the editor, right click on it and choose one of the following shortcuts from the context menu:

Commands:

  • Ask ChatGPT: will provide a prompt for you to enter any query
  • ChatGPT: Explain selection: will explain what the selected code does
  • ChatGPT: Refactor selection: will try to refactor the selected code
  • ChatGPT: Find problems: looks for problems/errors in the selected code, fixes and explains them
  • ChatGPT: Optimize selection: tries to optimize the selected code

Ask ChatGPT is also available when nothing is selected. For the other four commands, you can customize the exact prompt that will be sent to the AI by editing the extension settings in VSCode Preferences.

Because ChatGPT is a conversational AI, you can ask follow-up questions to the response. The conversation context is maintained between queries, so you can ask multiple questions in a row (this can be disabled in the extension settings.). If you aren't satisfied with an answer and would like to retry the request, click ctrl+shift+p and select Retry ChatGPT request. To reset the conversation context, click ctrl+shift+p and select ChatGPT: Reset Conversation.


Please note that this extension is currently a proof of concept and may have some limitations or bugs. We welcome feedback and contributions to improve the extension. Also check out CodeGPT extension that uses official OpenAI API and also supports other GPT3 models. If you enjoy this extension, please consider buying me a coffee โ˜•๏ธ to support my work!

Buy Me A Coffee

Credits

chatgpt-vscode's People

Contributors

easychen avatar kir-antipov avatar lucajaich avatar mpociot avatar timkmecl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chatgpt-vscode's Issues

Feature Request: Keep a scrolling history of the current chat.

It's a bit cumbersome to chat with the bot and having the chat history be wiped out with each new query. Often times we want to ask it follow up questions, but not forget the old replies if we don't like the direction or newer suggestions it is making.

Slow Response and Timeout Error when using ChatGPT in Visual Studio Code

Dear Author,

I hope this message finds you well. I have been using your ChatGPT extension for Visual Studio Code for the past few days, and initially, it was working great with fast responses. However, suddenly the extension started to respond very slowly, and eventually, I received a timeout error.

I have checked my network connection and I am confident that it is not an issue with my network. I have also compared my experience with the official ChatGPT web page, and it is working perfectly fine.

Upon reviewing the Visual Studio Code developer logs, I found the following error message: "ChatGPT error 404" and "TimeoutError: ChatGPT timed out waiting for response".

I would greatly appreciate it if you could help me resolve this issue. Let me know if there is any additional information that I can provide to assist with troubleshooting.

Thank you for your time and effort in creating this extension.

Best regards,
nothing

I've been doing some testing regarding 403 errors

So I dug into it and realized that even copying cookies from browser to browser using cookie management addons is tricky. Basically It would never accept the cookie as valid and just show me login page. But I made a breakthrough.

image

It seems that all these 3 cookies are essential to get logged. For example callback-url value if not same as it was with that specific session token will invalidate the session token. Host auth token also is important. And one BIG important thing is that all three cookies NEED to have Lax sameSite policy and they NEED to be Session cookies. Now surprisingly you don't need expiration date on the session token.

Also the cloudflare cookies are supposed to be on .chat.openai.com domain, the dot is also important it seems. Other than that you only need cf_clearance, the other two cookies will get generated again.

So yeah just the session token isn't enough

Conversation disappears with each query

  • I right click my code and click, "ChatGPT: explain selection"
  • In the sidebar, the extension helpfully explains the selected code.
  • I pose a subsequent question, such as "What langauge is this?"
  • It deletes the former code explanation and replaces it with the answer to my subsequent question

I can't seem to find a conversation history setting and a web search hasn't turned up a clear answer.

"You exceeded your current quota, please check your plan and billing details.",

Hi!

I installed this extension and added the API key from the address: https://platform.openai.com/account/api-keys

Unfortunately, I keep getting a response from the extension:

[ERROR] Error: ChatGPT error 429: {.
"error": {
"message": "You exceeded your current quota, please check your plan and billing details.",
"type": "insufficient_quota",
"param": null,
"code": null
}
}

I am using WSL Ubuntu 18 as a subsystem on Windows.

Is there perhaps a solution to this problem? Thanks!

How can I define system/user?

Well, once again, the title is self-explanatory haha. How do you indicate to the model in your extension the system/user? In GPT3.5, it may not be particularly important, but after seeing the release of GPT-4, it seems that the fact that it is multimodal will make the system field quite important.

regards

Custom option

It would be great to have a customizable option to add specific commands.

For example:
Custom Option: "Analyze complexity of this code"

[ERROR] 429 undefined

I just installed v1.1.2 and added the API key. Then I ask a question from the CodeGPT panel and the response is "[ERROR] 429 undefined".

It's worth mentioning that when I use ChatGPT on the browser, my company's security software will ask me to confirm that I want to use it. This security software popup is not showing up either.

Ideal solution to make this extension work without Errors

Hi Tim,

There's this other extension called vscode-chatgpt that has solved the Puppeteer issue and allows users to use this extension by running another window of Chrome in the background.

I tried it myself today, and it works quite well as it also allowed me to manually solve the captcha, and then it entered my username and password for me.

However, the problem with this other extension is that I really don't like their UI/UX and would vastly prefer the simpler experience of your extension.

Perhaps you could consider their approach of solving this problem and implement it yourself in this extension.

Kind regards,
(And I hope you had a happy holiday season โค๏ธ)
Welding-Torch

[ERROR] Error: ChatGPT error 429

[ERROR] Error: ChatGPT error 429: {
"error": {
"message": "You exceeded your current quota, please check your plan and billing details.",
"type": "insufficient_quota",
"param": null,
"code": null
}
}

Currently not working

Maybe it is my API key but I am getting [ERROR] TimeoutError: ChatGPT timed out waiting for response for everything

Feature Request: Ability to remove right click menu items

My menu items list is getting huge and this plugin, while great, is taking over. It would be great if we had an option to not include them in the right click context menu. I don't mind hitting F1 and asking for documentation or refactoring.

2023-03-03 - Right Click

Activation of extension failing when debugging

Steps to reproduce:

  1. Download the source code
  2. Open in vscode
  3. Run yarn install
  4. Hit F5 to debug it
  5. In the new vscode window, click on the ChatGPT extension icon on the dock

Error:

Activating extension 'timkmecl.chatgpt' failed: ENOENT: no such file or directory, open '/Users/jay/Downloads/chatgpt-vscode-main/dist/encoder.json'.

How do you debug it?

ChatGPT repies with How Can I help you today?

I have a paid account, I am using GPT 3.5 turbo, I have installed the latest version from the MarketPlace. If I do small amounts of code such as:

    getAllData: async function () {
      this.isLoading = true
      let data = await import('@/assets/data/data.json')
      this.billsTable(data)
      this.widgets(data)
      this.isLoading = false
    },

It works fine, although if I have it write a document for the entire code, it just returns:

Hello! How can I assist you today?

Is there a line or character limit? Is there a way to remove this limit?

Error 418?

Whenever i ask a question to test, it gives me error 418

Issue with Development mode: Missing 'tiktoken_bg.wasm' File

Hello, good morning,

I have downloaded the repository to experiment with the VSCode extension, but when trying to run it in development mode, I get the following error:

Activating extension 'timkmecl.chatgpt' failed: ENOENT: no such file or directory, open '/personal_directory/source/dist/tiktoken_bg.wasm'.

Could you help me with this?

Best regards.

Error 401 with chatgpt extension, vscode

whenever i put in a prompt, it gives me this error:

[ERROR] Error: ChatGPT error 401: {
"error": {
"message": "",
"type": "invalid_request_error",
"param": null,
"code": "invalid_api_key"
}
}

any help?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.