I'm doubtful, too. How would copilot know what to generate for the second function? How can get_depth_input be sufficient information to generate a function that reads a text file "input.txt" line by line and cast each line to an int? If copilot truly does that, then it's heavily geared towards toy problems.
That sounds like too much input. Remember that Copilot is based on GPT-3, so its input size is limited to 2048 tokens.
I think it's more simple to assume that "get_*_input" is a common name for a function that reads input from a stream and so that this kind of string is common in Copilot's training data. Again, remember: GPT-3. That's a large language model trained on a copy of the entire internet (the CommonCrawl dataset) and then fine-tuned on all of github. Given the abundance of examples of code on the internet, plus github, most short progams that anyone is likely to write in a popular language like Python are already in there somewhere, in some form.
The form is an interesting question which is hard to answer because we can't easily look inside Copilot's model (and it's a vast model to boot). The results are surprising perhaps, although the way Copilot works reminds of program schemas (or "schemata" if you prefer). That's a common technique in program synthesis where a program template is used to generate programs with different varaible or function names etc. So my best guess is that Copilot's model is like a very big database of program schemas. That, as an aside.
Anyway I don't think it has to peek at other open files etc. Most of the time that would not be very useful to it.
It's comments like these that make me wish I could stand behind the chair of the people who get these results because I feel like there's something lost in translation. I don't know if I'm taking your comment too literally but this part confuses me:
> It writes lots of code before I even think about what I was going to do in that file.
If you haven't even thought of what you want to do in the file, how are you prompting Copilot to write the code you need? Am I understanding correctly that Copilot not only generates the correct code, but it's also able to deduce what code you meant to ask for without any input from you? I don't see how this is possible except in the uncommon case where you are bringing a file to be more in line with other files in your code base that have a similar structure.
I do think Copilot can be useful, but I'm confused at how different my experience is from what others are getting out of the tool.
I can't get Copilot to generate Python that adds numbers together correctly sometimes. Getting an LLM to generate correct, working code for a language that hardly anybody writes anymore is almost assuredly going to lead to failure.
I've been writing a literate multi-file program in Go and Copilot has been partially compensating for the lack of tooling support, especially since Copilot can infer from prose.
I don't use Copilot but sometimes I ask ChatGPT to write some small algorithmic function. I describe the inputs and what it should do as I would do with you and most of the times it works. It saves me the time to check the reference. I keep working on the code calling that function while it's generating. When it doesn't do the right thing I attempt to explain me better. If I get a feeling that it's hallucinationg, I give up and write it myself.
No, it's code I would have written by looking things up from Stack Overflow anyway. Copilot doesn't actually really create novel algorithms, it's best used for boilerplate, in my experience.
That's not my experience at all. I find Copilot the best at understanding and making sense of my work context, spanning many files. I find it less useful for creating generic functions.
Copilot sends huge prompts continuously since it includes adjacent files for context. That's why it's so good at "figuring out" your own esoteric code.
I'm so confused when people say copilot is magical, or even particularly helpful. I used it for a few days, and it would offer interfaces that sounded right, but didn't exist, or it would try to implement an entire function for me that just trailed off into nonsense.
It was best at writing comments on a function that had already been written.
There were one or two times that it guessed correctly at code I wanted.
It seems like you tried used copilot did you? To me the best thing about it is not the full function generation, which doesn't work very reliably, it's to finish the end of the line, when you already know what you will type, and it just types it for you faster. It feels like magic and checking the code is extrême fast as it's just one line, much faster than writing it.
My experience has been similar. I recently wanted it to write code to parse and process a rather strange data file into a list & dict. Here is what I found:
I went through a process of re-writing my prompt several times to get correct output. In fairness, I think getting the correct result meant being more precise with the prompting language.
Overall, it was a bit spooky seeing it respond to my varying prompts; then noticing it's errors; then re-prompting to fix its misconceptions. In the end, though I could have written it myself faster, so I am not sure it is saving me time.
I am surprised when I see people saying its saving them massive amounts of time. Are there any good examples out there of it producing copious amounts of code, correctly, from prompting such that I can easily believe using CoPilot is a time-saver?
Heh this blew up here :D Didn't know till a friend told me about it.
I'd love to know if you guys have any specific questions about copilot's internals that I can try to answer by staring at the code or if you have any feedback for the tool/post!
GitHub Copilot is a much better tool that's actually made for coding. It works in your IDE and can read and understand the code you already wrote. It knows language syntax as well. Not free, but certainly no limits on code output or amounts.
MS has said that in their testing 50% of the programmer's output is from accepting prompts. I'd say that's accurate. In my use of Copilot, I never ask how to do something because I already know. But, when I start to do it, it magically fills in each line with my own functions and variable names, even when they are many files away. That is really useful!
There a probably 1,000 lines of code or more in my 30k line TS codebase where I knew what I would have to type -- and I didn't have to. Reading the correct line and saying, yeah, that's correct, is much faster than composing it, especially when it's full of curly braces inside arrays inside objects, etc.
It's the same with copilot; you have to know how to implement things to implement things with copilot (for the most part), but when you are a programmer and you could write the code, then you know the prompt to write to generate 10+ lines of code for 1 comment of text all day long. Especially for data transformation, copilot has been a real magic tool; if you put in a comment:
/*
this functions transforms this json from:
{
... some complex structure in json
}
to this json:
{
... some different structure in json
}
*/
... copilot comes up with the function that takes in the first and spits out the latter. Even if the fieldnames do not match etc, it usually 'guesses' right what fits on what (so it does have some context from it's learning phase what 'looks alike' or 'might be the same thing'. Example: I had a structure with firstName: string, lastName: string and a target structure with name: string; it just did name: firstName+' '+lastName, which was indeed what I wanted. But it comes up with more intricate stuff as well that is pretty much surprising (too human basically).
What is another bonus; if you generated function transfromAtoB(a: A) above, then you only have to do:
/*
do the reverse of function transfromAtoB, accept json structure B as input and return structure A
*/
And it'll come up with the reverse.
It's not hard to write yourself, but it's boring and error prone (some of these structures are huge). Now I press tab a bunch of times, and run the tests to see if it worked. I am also not that worried i'm infringing someone's open source code; this is all way to custom to look like anything else. That's where this shines; things where it verbatim copies something, you should've been using a library anyway.
Statically typing and using typescript definitely works better than other combinations I have tried (C# was pretty bad last I tried it, JS is good but often subtly wrong because of type issues).
You need to bait Copilot really hard to make it output that. To the point where it would be much easier to locate and copy-paste the code directly from the source yourself. It doesn't happen accidentally and it's not how you normally use Copilot.
Copilot doesn't recognize what you're trying to do and then paste a code sample from a repo it has in its index. Just like DALL·E 2 doesn't produce images that say "I picked these pixels from this image and this part from this other one and these colors from this third one". When a model is trained, it's effectively a set of hundreds of millions of numbers that when combined in just the right way can produce a specific output. In my experience the vast majority of the time Copilot doesn't write code that already exists. It actually uses the variables you declared, the functions that already exist in your code base, etc.
It's not an index of best matches from GitHub for what you're trying to do.
It is not even remotely usable with languages like Haskell, the code it generates almost never typechecks, IME. I think the primary reasons being lack of training data (there is far more Python code on GitHub than the entirety of Hackage) and that Copilot is essentially a language model that does not consider AST and type information at all.
I used copilot to learn the crufty parts of bash and to pick up swift from zero. The smaller the problem you're trying to solve the easier it is for copilot to generate it perfectly for you.
Think of it like a snippet engine on steroids. It's a huge value add.
reply