copilot-explorer icon indicating copy to clipboard operation
copilot-explorer copied to clipboard

How to invoke Github Copilot programmatically?

Open code2graph opened this issue 2 years ago • 9 comments

I am looking for a way to control GitHub Copilot programmatically, i.e., invoking it from code.

My question is how to capture the top suggestions provided by Copilot in an automated fashion.

For example, for any given autocomplete task to Copilot, the task is to record the code suggestions and save them into a file.

I am wondering whether your project can help on that?

code2graph avatar Aug 14 '23 13:08 code2graph

The best way I'm aware of doing this is to do UI automation on VSCodium with copilot installed. VSCodium has some UI tests in its repository, written using puppeteer. The tests show how to set the text of an editor to something, move the cursor around, etc. You can do that with copilot installed, and wherever you want a prediction, trigger a backspace and retype that character programmatically. Copilot will make an API call to the backend which you can gather, or modify vscodium to call your function whenever it shows an inline suggestion.

However I'd caution against automatically triggering copilot without ratelimiting as it would cause trouble for github and might cause your account to be flagged.

thakkarparth007 avatar Aug 14 '23 13:08 thakkarparth007

Thanks for your feedback. However, Puppeteer is for headless browsing automation of web apps. A bit confused how it would be applied directly to VSCodium? Could you clarify?

code2graph avatar Aug 16 '23 11:08 code2graph

@thakkarparth007 I don't find any code written with puppeteer for VSCodium: https://github.com/search?q=org%3AVSCodium+puppeteer&type=code.

Probably missing something here?

(Please note I do not plan to trigger copilot for a lot of suggestions. This is just for a few 100 suggestions)

code2graph avatar Aug 16 '23 11:08 code2graph

My bad I confused VSCodium as something else. Here's a link to one test that launches some editor, changes some text, closes vscode without saving, and restarts to see if the text has survived.

https://github.com/microsoft/vscode/blob/main/test/smoke/src/areas/workbench/data-loss.test.ts

There are many other tests in this "test/smoke" folder. They should help you. But you'll still need to figure out installing the extension (should be a matter of placing it in VSCODEROOT/extensions), and dealing with auth.

VSCODEROOT for the open source version of vscode is not ~/.code. I forgot the name but once you run some test there'll be a new folder in your home folder. You should be able to identify it.

thakkarparth007 avatar Aug 16 '23 16:08 thakkarparth007

hey @code2graph did u find any way to do that ? I'm very interested

elsayed85 avatar Aug 19 '23 12:08 elsayed85

@elsayed85 can't yet figure out a concrete plan to achieve this. Will keep you informed.

code2graph avatar Aug 20 '23 07:08 code2graph

@elsayed85 can't yet figure out a concrete plan to achieve this. Will keep you informed.

@code2graph im working now on copilot chat and i know how it works .. the full request from being to end .. also copilot complete

elsayed85 avatar Aug 20 '23 07:08 elsayed85

@elsayed85 would love to know how you achieved this.

code2graph avatar Aug 28 '23 05:08 code2graph

@code2graph sure u can dm me in twitter or LinkedIn

https://www.linkedin.com/posts/elsayed85_github-copilot-chat-cli-using-laravel-activity-7099244597742088192--Rp1?utm_source=share&utm_medium=member_ios

elsayed85 avatar Aug 28 '23 05:08 elsayed85