Train Codex using GitHub Repositories

Hello, I’m trying to create a model that will write code for a robot. I was wondering if I could somehow increase Codex’s knowledge of this Github repo: GitHub - FIRST-Tech-Challenge/FtcRobotController as well as its forks, thanks.


@pabhiram05 You can load the repo’s individual files as docs into /answers, with cushman-codex as the search_model, and davinci-codex as the completion model. You will have to prompt the endpoint with a question, examples_context, and examples, in order to steer it to generate the kind of code you want.

Alternatively, since the base gpt3 models are also good at coding, you can finetune davinci or curie on the files of the repo using completion-only finetuning.


Thank you so much, I’ll try this as soon as I can.

1 Like

@asabet Is there a way I can do this without needing to pass in examples and context? If not, is there a way I can generate them based on the question? Also, are files only taken in a jsonl format?

Good question @pabhiram05. You don’t need to change examples_context and examples for each question, just one or two demonstrations (ie state objects as examples and a function definition as examples_context) to control what the completion should look like overall.

Thinking more about it, a better strategy might be to combine search with completion directly instead of using /answers. Suppose you want to auto-generate code for an existing file (ie an init method for an BasicOpMode_Iterative class), you can query the search endpoint with the preceding code:

package org.firstinspires.ftc.robotcontroller.external.samples;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.ElapsedTime;
import com.qualcomm.robotcore.util.Range;

@TeleOp(name="Basic: Iterative OpMode", group="Iterative Opmode")
public class BasicOpMode_Iterative extends OpMode
    private ElapsedTime runtime = new ElapsedTime();
    private DcMotor leftDrive = null;
    private DcMotor rightDrive = null;

    public void init() {

then load the retrieved docs into davinci-codex's context along with the query like:


and let codex run. You should also insert comments where necessary in order to improve steerability. There are lots of heuristics you can then use to optimize behaviour. Off the top of my head:

  1. Use individual classes for your search docs instead of raw files, which would save space and improve relevance.
  2. Extract code from imports and insert into context instead of using raw search (saves space, improves relevance, less costly, etc).
  3. Retrieve the base class for the derived class you’re extending (OpMode in this example)
  4. Store codebase as embeddings.

The complexity of the implementation will grow rapidly depending on your use-case, so it’s probably best to limit the scope of the code you want it to write, and integrate into an IDE as a plugin (like copilot) to take advantage of existing functionality like its language-server.