• Stars
    star
    140
  • Rank 261,473 (Top 6 %)
  • Language
    Python
  • Created over 1 year ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A self-hosted github copilot guide using oobabooga webui

localCopilot

donate here

This project allows you to host your own GitHubCopilot-like model locally while using the official GitHubCopilot VSCode extension.

Installation:

  1. Download and install the oobabooga backend

  2. Download a model

    open the oobabooga UI, go to the models tab and download a code completion model. I'm using: Deci/DeciCoder-1b, paste that name, then click download, then click load once complete

    Which model should I choose? Use smaller models for faster predictions, especially if you have a weaker PC. I tested DeciCoder-1b

    size speed model name
    125M superfast flax-community/gpt-neo-125M-code-clippy-dedup-2048
    1B fast Deci/DeciCoder-1b
    3B medium TheBloke/stablecode-instruct-alpha-3b-GGML
    7B slow mlabonne/codellama-2-7b
    15B slow TheBloke/WizardCoder-15B-1.0-GGML

Optional testing

A. (optional) Test the backend using curl:

```sh
curl -X 'POST'   'http://localhost:5000/v1/engines/codegen/completions'   -H 'accept: application/json'   -H 'Content-Type: application/json'   -d '{"prompt":"def hello_w","suffix":"","max_tokens":500,"temperature":0.4,"top_p":1,"n":10,"stop":["\ndef ","\nclass ","\nif ","\n\n#"],"logprobs":2,"stream":true}'
```

B. (optional) Test that the model is working by going to the "chat" tab and clicking "generate".

  1. Go to VSCode and modify the settings and add the following:

    "github.copilot.advanced": {
        "debug.overrideEngine": "codegen",
        "debug.testOverrideProxyUrl": "http://localhost:8000", // address:port of middleware
        "debug.overrideProxyUrl": "http://localhost:8000",
    },
  2. (optional for authentication) Update ~/.vscode/extensions/github.copilot-*/dist/extension.js with the following:

    • Replace https://api.github.com/copilot_internal with http://127.0.0.1:8000/copilot_internal
    • replace https://copilot-proxy.githubusercontent.com with http://127.0.0.1:8000
  3. Run the proxy:

    pip install git+https://github.com/FarisHijazi/localCopilot
    localCopilot --port 7000

    If you have oobabooga running on a separate server use the --backend argument {hostname:port}

    pip install git+https://github.com/FarisHijazi/localCopilot
    localCopilot --port 8000 --backend http://10.0.0.1:5002
(Optional): testing the middleware
curl -X 'POST'   'http://localhost:8000/v1/engines/codegen/completions'   -H 'accept: application/json'   -H 'Content-Type: application/json'   -d '{"prompt":"def hello_w","suffix":"","max_tokens":500,"temperature":0.4,"top_p":1,"n":2,"stop":["\ndef ","\nclass ","\nif ","\n\n#"],"logprobs":2,"stream":true}'

expected output

data: {"id": "conv-1692741316942825472", "object": "text_completion.chunk", "created": 1692741316, "model": "Deci_DeciCoder-1b", "choices": [{"index": 0, "finish_reason": "stop", "text": "", "logprobs": {"top_logprobs": [{"<|endoftext|>": -0.4215908944606781, "<fim_middle>": -1.2965909242630005, "\n": -3.0741329193115234}]}}], "usage": {"prompt_tokens": 4, "completion_tokens": 13, "total_tokens": 17}}

data: [DONE]
  1. install the official GitHub copilot extension

  2. HAPPY CODING!

    To test that the copilot extension is working, either type some code and hope for a completion or use the command pallet (Ctrl+Shift+P) and search for GitHub Copilot: Open Completions Panel


How this works

This is done using a single script: localCopilot/middleware.py (only 90 lines of code), which is a compatibility layer between the official GitHub copilot VSCode extension and oobabooga as a backend.

Credit: I learned about the traffic redirecting from the Fauxpilot project here.

Cloud
Self-hosted
Advanced experimental hacks

The tokenizers used by Copilot are not the same, so you can overwrite them. However, I'm not sure how useful this actually is as I don't notice any change in performance

COPILOTPATH=$HOME/.vscode/extensions/github.copilot-1.105.353
MODELPATH=$HOME/Projects/oobabooga_linux/text-generation-webui/models/Deci_DeciCoder-1b

mv $COPILOTPATH/dist/resources $COPILOTPATH/dist/resources.backup
mkdir -p $COPILOTPATH/dist/resources/cushman001
mkdir -p $COPILOTPATH/dist/resources/cushman002

cp $MODELPATH/tokenizer.json $COPILOTPATH/dist/resources/cushman001/tokenizer_cushman001.json
cp $MODELPATH/merges.txt     $COPILOTPATH/dist/resources/cushman001/vocab_cushman001.bpe

cp $MODELPATH/tokenizer.json $COPILOTPATH/dist/resources/cushman002/tokenizer_cushman002.json
cp $MODELPATH/merges.txt     $COPILOTPATH/dist/resources/cushman002/vocab_cushman002.bpe

And to revert your changes, just uninstall and reinstall the extension.

OR:

rm -rf $COPILOTPATH/dist/resources
mv $COPILOTPATH/dist/resources.backup $COPILOTPATH/dist/resources

😁 Benefits of self-hosting

  1. πŸ” Privacy: No more sending your code to the cloud! This is the main benefit especially for enterprise. No code is sent to the cloud when self-hosting since everything runs on your machine(s).
  2. 🌐 Works without internet: use it on the plane! ✈️
  3. πŸ’° Free: No need to pay for your monthly subscription

😞 Limitations

  1. GitHub copilot looks at multiple files for context. The current hack only looks at the current file
  2. Quality Open source models might not have suggestions as good as copilot, but still as good most of the time
  3. GitHub copilot gives 10 suggestions, while this hack gives only 1 suggestion per completion
  4. πŸ› There's a bug where the first space in autocompletion is skipped, this is due to the oobabooga backend, not the model

Why is this project setup this way?

There are many other projects for having an open source alternative for copilot, but they all need so much maintenance, I tried to use an existing large project that is well maintained: oobabooga, since it supports almost all open source LLMs and is commonly used, and is well maintained

I know that the middleware method might not be optimal, but this is a minimal hack that's easy to run, and this repository should be really easy to maintain.

Once oobabooga supports multiple requests in a single call, then the middleware should no longer be needed.

Other works

Here are some helpful open source projects I found while doing my research:

Project URL description actively maintained (as of Aug 2023)
https://github.com/CodedotAl/gpt-code-clippy Frontend + models ❌
https://github.com/Venthe/vscode-fauxpilot this is a FauxPilot frontend βœ…
https://github.com/hieunc229/copilot-clone frontend which uses Google/StackOverflow search as a backend βœ…
https://github.com/fauxpilot/fauxpilot FauxPilot backend βœ…
https://github.com/ravenscroftj/turbopilot A backend that runs models βœ…

More Repositories

1

Rarbg-Enhancer-UserScript

Browser extension for Rarbg.to to add autoCAPTCHA, magnet links, and enhance the interface
JavaScript
108
star
2

rarbgcli

RARBG command line interface for scraping the rarbg.to torrent search engine
Python
51
star
3

SuperGoogleImages

Userscript to Super-charge Google images with rich features, like: download all full-resolution images, replace thumbnails with full-res images, add "view image" and "download" buttons and much more
JavaScript
31
star
4

deblack

remove black frames from a video. Simple python file to create ffmpeg commands. Originally started in a stackexchange question (https://superuser.com/a/1697654/739491)
Python
19
star
5

commands

here I keep all my useful linux commands for setup and for managing files and folders
Python
17
star
6

Secure-FileTransfer

A python implementation for secure file transfer. Course project: "Cyber Security" (KFUPM-COE451)
Python
15
star
7

TwitterDownloader

Download images from twitter bookmarks and likes feed
JavaScript
11
star
8

Face-Generation-GAN

Generating Anime faces with GenerativeAdverserialNetworks using PyTorch
Jupyter Notebook
9
star
9

LZ4-Decompressor-Verilog

Designing and implementing LZ4 decompression algorithm in hardware (FPGA) using Verilog hardware description language
Verilog
8
star
10

10FastFingers_BotAntiAntiCheat

10fastfingers.com auto-typer bot, can also bypass anticheat using OCR
JavaScript
6
star
11

UnityNetworkPacketTracer

A small Unity library written in C# to help simulate network traffic (mostly at the application and transport layers)
C#
2
star
12

pause-other-audios-browser-extension

Pauses any other audio element once you click on a new one
JavaScript
2
star
13

JupyterNotebookUserScript

helpful userscript (tampermonkey) to add my most used functionalities to jupyter notebooks
JavaScript
1
star
14

CodExp

understand your codebase with static code analysis and LLM agents
1
star
15

llm-lab

a place to quickly run notebooks and try out and fix and hack and evaluate LLMs, inspired by: https://github.com/utensil/llm-playground
Shell
1
star
16

VisualPollutionDetection-GlobalAISummit-SDAIAsmartathon

Python
1
star
17

distributed-GPUs

learning about distributed GPUs through Ray, SLURM, PyTorch, and other tools
Python
1
star
18

FarisHijazi

1
star
19

MISAssSim

"M Instruction Set Architecture Assembler and Simulator". Simple assembler and simulator made with python. Specific to the M-Architecture
Python
1
star
20

multimodal-emergency-classification

Classifying emergency reports from texts, images, audios, videos with BLIP + ChatGPT
Python
1
star
21

DuckDuckGo-Enhancer

This script adds features to DuckDuckGo.com image search.
JavaScript
1
star
22

win_setup

PowerShell
1
star
23

DeepLearningHandsOn

Jupyter Notebook
1
star
24

ai-notebooks

simple notebooks used to demonstrate concepts from Artificial Intelligence (AI), Machine learning (ML), and Deep Learning (DL)
Jupyter Notebook
1
star
25

DigitizedAttendanceSystem-ComputerVision

Taking attendance using facial recognition - part of the COE485 Senior Design project for Term 192
1
star