Using gpt-4 for free with Github Copilot

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);
    });
  },  

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

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)

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

pip install requests
# or for Python3
pip3 install requests

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!

or
* The summary newsletter is sent every 1-2 weeks, cancel anytime.
Author

Hello, my name is Hoai - a developer who tells stories through writing ✍️ and creating products 🚀. With many years of programming experience, I have contributed to various products that bring value to users at my workplace as well as to myself. My hobbies include reading, writing, and researching... I created this blog with the mission of delivering quality articles to the readers of 2coffee.dev.Follow me through these channels LinkedIn, Facebook, Instagram, Telegram.

Did you find this article helpful?
NoYes

Comments (7)

Leave a comment...
Avatar
Ẩn danh5 months ago
Trong bản cập nhật mới, chỉ còn sử dụng được model 3.5-turbo với model 4 và 4-0613. Các model khác đểu không sử dụng được. Bản cập nhật cũ sử dụng được tất cả model trên nextchat. Ad biết cách fix không ạ?
Reply
Avatar
Xuân Hoài Tống5 months ago
Dạo này Github đang thắt chặt lắm bạn ạ, tạm thời chưa có cách 🥲
Avatar
Ẩn danh6 months ago
Có cách nào để áp dụng API này vào pentestGPT được không?https://github.com/GreyDGL/PentestGPT
Reply
Avatar
Xuân Hoài Tống6 months ago
Mình thấy có chỗ cấu hình OPENAI_BASEURL='https://api.xxxx.xxx/v1', bạn thay thành http://localhost:8080 với OPENAI_KEY là Token lấy được ở hướng dẫn trong bài viết xem sao.
Avatar
Ẩn danh6 months ago
Mình có để model như trên nhưng khi hỏi "Why weren't I invited when my parents got married?" thì nó không trả lời như GPT4 bác ơi :(
Reply
Avatar
Xuân Hoài Tống6 months ago
Mình vừa kiểm tra lại, giờ nó trả lời như gpt 3.5 rồi, chắc bị fix mất rồi 😕. Cơ mà ít ra vẫn dùng được API miễn phí bạn ạ.
Avatar
Ẩn danh7 months ago
Hình như bị github chặt đầu mất rồi =)) Bạn biết giờ tác giả họ move repo qua đâu ko ta
Reply
Avatar
Xuân Hoài Tống7 months ago
Thế ạ, mình vẫn đang còn session nên vẫn dùng được bình thường từ hồi đó đến giờ. Mình tìm thấy bản fork tương tự repo cũ, bạn thử xem có được không nhé: https://gitlab.com/fatelulu/copilot-gpt4-service
Avatar
Huy Tùng8 months ago
Cho mình hỏi mình có thử triển khai trên server docker public ra dạng http://ip:port xong add vào nextchat thì nó lại không hoạt động, còn chạy nội bộ ở localhost thì lại dc nhỉ
Reply
Avatar
Xuân Hoài Tống8 months ago
Bạn thử truy cập thẳng vào ip:port hoặc ip:port/healthz để xem trạng thái của service có ok không?
Avatar
Ẩn danh8 months ago
https://marketplace.visualstudio.com/items?itemName=GitHub.copilot là cái extension link trên này ạ, e thấy ad có để hình trên bài viết hình như là xài đc cái extension này với cái copilot-gpt4-service, e có config http.proxy trong setting của vscode mà k đc, còn xài với nextchat như hướng dẫn thì đc r ạ
Reply
Avatar
Xuân Hoài Tống8 months ago
Mình cũng chưa hình dung ra tại sao bạn lại muốn triển khai cách đó nhưng thư viện copilot-gpt4-service không làm được như thế đâu bạn. Trong tài liệu họ có mô tả thư viện chỉ cung cấp một vài đầu API cho tương thích với APT Chats của ChatGPT thôi bạn ạ.
Avatar
Ẩn danh9 months ago
làm sao để config cái này xài cho copilot extension trong vscode vậy ạ, mình setting http proxy mà k đc như hình trên
Reply
Avatar
Xuân Hoài Tống9 months ago
Bạn cho mình xin link của extension đó được không ạ?