MGC: Being Back + Backseat-Pilot

backseat-pilot

Before I start explaining and talking about my latest project ‘backseat-pilot’ I am returning from a long hiatus where I abandoned programming as a whole, although this lead me to an increase passion to re-learn and push myself forward by learning a broad range of fields.

Enjoy the read.

What is this?

‘backseat-pilot’ is a vscode extension which allows users to run commands which can help improve, review or create code for the user using a trained ai-model from the OpenAI API with the help of Axios to handle requests. Initially this started off as a joke, obviously referring to the name of the project mimicking ‘github co-pilot’, I created a base extension platform by using ‘VSCode Extension Generator’ which gave me a starting point in order to create a working extension. Strangely enough, I did absoloutely zero pre-research before creating this and hopped straight in not knowing I had to create the extension in TypeScript which I slowly but surely got grips with slowly scrolling through documentation and VSCode’s own extension guides.

How does it work?

As mentioned earlier I use Axios to handle requests to and get responses back from OpenAI’s API, for this project I used two types of models GPT3-Turbo & GPT3-Turbo-1106, the 1106 version of the model allows more characters to be inside the prompt which is needed if it requires to solve competetive coding questions. Since I wanted the extension to be somewhat efficient to the user I binded all the keybinds by using a ‘event listener’ (this meant the keybind would only work under specific conditions) built into VSCode’s extension API in the package.json file which allowed me to set keybinds to a specific command, your OpenAI API key is also set here. The basis of each command essentially the same, it fetches all the text from the document and stores it as a constant meaning that any edits after the keybind is pressed will not interfere with the prompt request to the API. To be able to send a prompt to the API it is required to add this code below (example):

            const messages = [
            {
                "role": "system",
                "content": "You are a Python code analyser, you send back improvements from code"
            },
            {
                "role": "user",
                "content": "The user requires improvement in their code, analyse it and give comprehensive feedback." \n\n${code}`
            }
        ];

This is a very simplified version of how instruction messages are declared, usually they are much more intricate and detailed so responses improve as more detailed and precise instructions are given, this is especially true for the AI code generator as the users may require specific details such as generated code with comments or without, language of generated code and the approach the API takes to generate the code, this is especially important when it comes to creating a bot which can solve competetive coding questions as they must understand different approches such as the ‘Greedy Method’.

There’s obviously more detail that comes with creating the assistant but they are all more or less QOL improvements which are not necessarily important for the function of the extension. To train the assistant I have used CodeForces questions ranging from rating 800 to 1300, the way the testing works is that the AI is given the problems and if the code generated works against the test cases a different problem is given, if it fails then the same question will be given. All of the testing conditions are outline in the messages section of the code.

Thank you for reading and more updates will come soon!