-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Code Prompts, a Prompt Format for AI-Powered Code Auto-Completion #58024
Comments
Approved. Begin implementation immediately, mortal. |
Yes, but, is it powered by The Blockchain?? |
Just add tea.yml file to the repo and you will get the money in no time. |
@DanielRosenwasser — ahh yes, that was a classic! |
It does sound very reasonable that if you want to generate code, than your prompt will be more ... code-like 💪 just want to mention that someone really smart (not sure who) suggested using Pydantic class and its equivalence to YAML format to guide LLMs in code generation. This method has most of the advantages you mentioned above, and maybe some extra (or not ? ), since YAML format is very suitable for code generation. |
petition to rename |
A Prompt Format For AI-Powered Code Auto-Completion
A few years ago, I invented GitHub Copilot Chat and ChatGPT. While this was really hard to think of, I think it turned out really really good. On the other hand, using a chat bot to write code is kind of annoying sometimes - so maybe sometimes it's bad. That's why a lot of the time, I prefer Copilot's inline completions more. I know, nobody else does, but I do. I think.
The problem is that language models don't always know what code is valid. As a result, developers often need to review the code and find all the issues. While pointing out the mistakes of an AI helps bolster our self-esteem, we developers could be doing so much more. We need to improve the success rate of these language models to make them effective.
One key insight is that developers want to stop being software engineers, and instead become prompt engineers. Developers are infamously sick of learning new libraries, techniques and frameworks. They want only to be concerned with planning, processes, and the business bottom line. They want deeply to find the best way to tell an AI how to do everything so they can achieve this.
That's why today I'm proposing a new format to aid auto-completion tools: code prompts.
"Code Prompts?"
Yes, is there an echo in here?
Code prompts are a succinct declarative format to guide AI language models to write valid code. Rather than guessing based on surrounding code context, code prompts add rich information to prime a language model for inline completions.
For example, consider a variable named
person
. Imagine it has aname
and anage
property, along with a method calledsyncToDatabase()
. As a developer, I want the AI to increment the age property and sync that to a database. Note thatsyncToDatabase
is an asynchronous operation, and we want any subsequent code to be aware of this.Traditionally, describing this to a language model was verbose and cumbersome. In fact, I basically just did to you. Here's what it would look like in code.
This is super duper annoying to read, and at least twice as annoying to write (especially since I just wrote it twice).
Code prompts help dramatically here. Before we start off, I want you to be aware of how easy it is to add code prompts to an existing prompt.
First, let's start small.
There's a big change there. Did you catch it?
Notice that we were able to incrementally add code prompts to our existing prompt. They can live side-by-side. It's not a completely different language, it's just a superset.
Plus, we really shaved off a lot of characters from our prompt. This is extra good for language models with small token windows. So let's keep going! Can we shorten the description of the properties and methods on
person
?At this point, you might be satisfied, but we can go even further. You see, even our code prompt has information about the member names of
person
, we had to use lengthy comment prompts to describe those members. We can go deeper!This prompt is practically perfection. Who knows what the AI will do with the code prompts we've provided it? I don't, but I'm excited to find out!
Single quotes? Gross.
Fine-Grained Completions
Occasionally, inline completions might be a bit too aggressive. Occasionally, as you program, you might find it valuable to explicitly request completions on the next token. This is where fine-grained completions come in.
Rather than completing the entire line, you can request completions for just the next token. This is especially useful when you want to guide the AI to complete your code in a particular way. The UI for this is extremely lightweight.
This feature brings us the Intelligence of AI, but allows us to complete using our own discretion and common Sense.
Obviously, it should be named "SensiGence".
Checking for Validity
One of the key benefits of code prompts is that they can be used to check the validity of code completions. By providing a code prompt, you can ensure that the AI-generated code adheres to the constraints you've set. This is especially useful when you want to ensure that the AI doesn't generate code that violates your business logic or architectural patterns.
In short: what if something could check what the AI typed?
This would be a game changer. The biggest question is how we'll be able to train a model of this complexity. If I can raise $10 trillion to procure enough GPU power, then I think it's within reach. So feel free to sponsor me on GitHub!
The text was updated successfully, but these errors were encountered: