DEV Community

Cover image for Using gpt-4 for free with Github Copilot
hoaitx
hoaitx

Posted on • Originally published at 2coffee.dev

Using gpt-4 for free with Github Copilot

The Issue

Hello readers of 2coffee.dev! It's just a few days left until the Year of the Quý Mão officially comes to an end, making way for the new Year of the Giáp Thìn with hopes of more success. This may also be the last article in the old year that I want to dedicate to all of you.

A few days ago, I wrote an article Transforming ChatGPT into an "Expert", in which I mentioned the issue of using the ChatGPT API to be able to use the "expert" because only in the API can we set up the system role, which helps ChatGPT narrow down the context and provide more accurate answers.

API calls to ChatGPT are paid, depending on the GPT model you are using. Honestly, I have tried every possible way to use the API for free, but all efforts have been in vain.

Yesterday, while "browsing" on Github, I stumbled upon a code repository that allows us to use gpt-4 for free through Github Copilot. Yes, you heard it right, completely free as long as you have a Github Copilot account.

For those who don't know, Github Copilot is an AI assistant developed by Github, which helps us with coding. Personally, I have been using Copilot for over a year and realized that its benefits are worth $10 per month. Yes, you heard it right! I mean, you need to spend $10 per month to use Copilot. If you're interested, I might write an article about Copilot in the future.

Therefore, the prerequisite for using gpt-4 for free is to have Github Copilot. Next, let's see how to leverage gpt-4 from Copilot!

Copilot and Copilot Chat

If I remember correctly, Copilot was introduced by Github before the ChatGPT model was widely announced worldwide. When I heard that Copilot was about to be released, I was curious to see what it was. They described Copilot as a real coding assistant, meaning that it would write code with us, based on what we have written or want to write.

After OpenAI announced the GPT model, developers started integrating it into their products to make them smarter and more interactive. Instead of clicking buttons and selecting features, now you can directly communicate with the product through text or voice, and it will immediately understand and help you with that task.

Copilot is no exception, and the Copilot Chat Beta feature was introduced shortly after the release of ChatGPT. Basically, it is integrated into the Editor/IDE, which are code editors, so Copilot Chat has the context of the code you are writing, allowing it to understand more about the context and provide accurate answers to your questions.

Here is an example of source code for the mounted function of my search page:

  async mounted() {
    await this.fetchResult();

    if (!this.isHasResult) {
      this.resetLimitOffset();
      await this.fetchOtherResult();
    }

    process.nextTick(() => {
      this.isMounted = true;

      setTimeout(() => {
        window.lazyload();
      }, 1500);
    });
  },  
Enter fullscreen mode Exit fullscreen mode

Let's ask Copilot to explain what mounted does, and here is the result:

Asking Copilot to explain

In general, Copilot Chat uses the "GPT model" to answer our questions. Therefore, someone on Github has taken advantage of this to use gpt-4 outside of code. This means that the context of use is no longer limited to code, and you can ask it any question, even turning it into an "expert".

Some may wonder why not chat directly with Copilot Chat? Well, Github has gone a step further and blocked unrelated questions to code, only answering relevant questions.

Do you remember NextChat (ChatGPT Next Web)? After some simple setup, it is now working with gpt-4 from Copilot Chat instead of the OpenAI API key, which means there is no more cost for API calls.

At this point, many readers are probably eager to try it out. That's why I have explained in detail how the copilot-gpt4-service tool is leveraging gpt-4.

Setup

copilot-gpt4-service is the mentioned code repository at the beginning of the article. "Convert Github Copilot to ChatGPT" is a very concise description that goes straight to the point, allowing you to create a local gpt-4 server based on your Github Copilot.

However, before using it, there are a few very important notes: only use it for personal purposes, preferably for personal use only, because your Copilot account or even Github account may be banned if abused.

Basically, when you start up this code, it will create a proxy server to ChatGPT. Do you remember the ChatGPT API address? It is https://api.openai.com. After deploying with copilot-gpt4-service, a local address is created for connection, which is http://localhost:8080.

If you use Docker, the fastest way to create a server is with a single command:

$ docker run -d \
  --name copilot-gpt4-service \
  --restart always \
  -p 8080:8080 \
  aaamoon/copilot-gpt4-service:latest
Enter fullscreen mode Exit fullscreen mode

You will need to take an additional step to obtain the GitHub Copilot Plugin Token, which can be used instead of the OpenAI API key. The process is quite simple, here is an example for MacOS/Linux:

$ python3 <(curl -fsSL https://raw.githubusercontent.com/aaamoon/copilot-gpt4-service/master/shells/get_copilot_token.py)
Enter fullscreen mode Exit fullscreen mode

But before that, you need to install the requests library for Python:

pip install requests
# or for Python3
pip3 install requests
Enter fullscreen mode Exit fullscreen mode

Then follow the detailed instructions in the returned result.

Finally, go to the configuration settings in NextChat.

Configuring settings in NextChat

Let's try to see if gpt-4 is working!

Testing if gpt-4 is working

If you don't believe that the above model is gpt-4, the author proposed a way to verify it by asking a question: "Why weren't I invited when my parents got married?". gpt-3.5 answers with the meaning "They considered you too young at that time, so they didn't invite you.", while gpt-4 answers accurately with "They got married before you were born".

You can also deploy this GPT server on the internet with some security configuration parameters as instructed. However, no matter how you do it, remember to use it for personal purposes only!

Top comments (7)

Collapse
 
july59 profile image
July Worth

That's a great idea. It looks innovative. Moreover, the idea about that either it is 3.5 or 4.0 is really interesting. I will take help from it in accomplishing my daily tasks. Thank you. I will take ideas from it whenever I will write articles or blog post for my site; Latest & Active WhatsApp Group links.

Collapse
 
hoaitx profile image
hoaitx

Great, hope that helps you.

Collapse
 
ba2sakal profile image
ba2sakal

Can't reach to the py file to get the token. Could you help or share the code somewhere, please? Thanks.

Collapse
 
hoaitx profile image
hoaitx

It seems that the repository on Github has been deleted due to policy violation. I tried searching and found that someone else has forked this source code. You can view it at gitlab.com/fatelulu/copilot-gpt4-s....

Collapse
 
edgessky profile image
Muhammad Yusuf Haidar Khairullah 20022

Seems that it's been nerfed lol. Yesterday I was fine with gpt 4 turbo and gpt 4o but now I'm limited to gpt 4 and gpt 3.5

Collapse
 
hoaitx profile image
hoaitx

Yes, there is a 'purge' happening from Github.

Collapse
 
bassam_elashkar_c026a2d1 profile image
Bassam El-Ashkar

is this still working? i get this error.

An error has occurred with OpenAI API, which is usually caused by incorrect settings or account issues. Please check your AI settings and account status, or click here to view the FAQ document.

API Error: Status Code 403, {"code":403,"error":"{\"error_details\":{\"url\":\"support.github.com?editor={EDITOR}... only use approved clients for Copilot. You are currently logged in as HIDDEN.\",\"title\":\"Copilot Unavailable\",\"notification_id\":\"go_http_client\"},\"message\":\"Resource not accessible by integration\"}"}

2024-08-27 13:26:46 ERR Get GithubCopilot Authorization Token Failed, StatusCode: 403, Body: {"error_details":{"url":"support.github.com?editor={EDITOR}... only use approved clients for Copilot. You are currently logged in as HIDDEN.","title":"Copilot Unavailable","notification_id":"go_http_client"},"message":"Resource not accessible by integration"}