by anotherpaulg · 3y ago · 0 comments
Here are some of my thoughts on how to code with chatgpt. Many overlap with topics covered in the Nature article.
- It really does help to think of chatgpt as a junior coder. I mentioned this in the writeup about my first AI coding project [2]. A bunch of things in this list would also be helpful when working with a junior dev.
- GPT isn't good at code architecture. It will repeat code and take the shortest, laziest path to coding up your request. You need to walk it through changes like you might with a junior dev. Ask for a refactor to prepare, then ask for the actual change. Spend the time to ask for code quality/structure improvements.
- Don't copy-and-paste between a chat session and your files. Use a tool like Copilot [3] or aider [0] that will give GPT your code to edit and apply its changes automatically. This is critical as it removes friction and lets you iterate quickly on code with GPT.
- GPT is amazing at generating fresh new self-contained code. It takes more skill and better tools to work with it to edit existing code.
- Break down a big change and ask for a series of smaller, self contained steps. This is a smart way to code solo, but really helps GPT succeed at more complex code modifications.
- GPT has a wide breadth of coding knowledge, and impeccable command of syntax... but it is sometimes overconfident about details. So it will usually choose the right library for a task, but sometimes make an error about the details of the api/method/params. Paste doc snippets or error messages into the chat and it will fix those bugs.
- GPT is really strong at churning out good boilerplate and roughing in a solution. This reduces the activation energy required to start larger changes or changes which will require unfamiliar libraries/packages/languages. GPT can can quickly prepare the ground for you to do the interesting work.
- If you can, use gpt-4 (not gpt-3.5-turbo) since it can successfully generate larger, more complicated code changes.
[0] https://github.com/paul-gauthier/aider[1] https://news.ycombinator.com/item?id=36020809
I've also been working with the APIs directly for about that time and I only get more depressed daily reading the horrible takes about GPT's problems based only off of ChatGPT (and hearing about how even many companies try to use the product). GPT has forever changed how I interact with computers.
I was using CodeGPT but this looks better. And it's exciting to have those command line options to easily insert other contextual input like command outputs.
Can I ask about your plans? CodeGPT planned to add semantic embeddings of code, but I haven't seen any updates for quite a time. The idea being that, like walking an Abstract Syntax Tree of the code, you could include relevant functions and function definitions(/classes/constants/etc), to help improve output quality.
Alongside what you note with module/library versions and pasting in doc snippets, I have often found is necessary to include package.json files to nudge the results towards the right API calls. I think semantic code search might push it finally to being able to work even on comprehensive, multi-service style repos.
For MVC or services architected solutions, I think this could be more helpful than including whole files - though it may be overkill - do you have any thoughts on doing this?
Yes, aider already has features to provide GPT with "code context" to let it edit larger, more complex codebases. I wrote up some notes about these features:
https://aider.chat/docs/ctags.html
You might be especially interested in the "future work" section near the end. I have actually shipped some of these ideas into the tool already. I need to find some time to write up the details.
Great to see, thanks again for developing it.
These are all good tips and very much align with my experience over the months, but breaking a complex task into as small, self-contained and logical steps as possible is truly going to make the biggest difference for most people.
Once I understood that, just like previous versions (GPT-3), ChatGPT has no internal memory beyond what has been typed, that changed how I interacted with the model for the better. Depending on the task, I am either providing simple steps or asking the model to write simple steps based on my task layout, then I provide input on those, ask for refinement of said steps with a focus on code generation and remove anything superfluous/not focused on code creation, the output quality became significantly more consistent and usable.
I can understand why, for a lot of more experienced developers, this can seem tedious and fully get why this leads a lot of observers to feel that, considering the effort required to set these models up for success, they might as well code themselves, especially considering this setup process can eat into the precious 25 prompts limit, which I hit consistently.
However, I feel that once these models have become more efficient, a lot of this outlining may be handled in the background.
The same goes for checking code errors in my eyes. For the same reasons (no internal memory), there often can be errors in provided code, yet asking for the model to check for errors generally resolves those. In most cases, this works without providing compile errors, though those of course do improve the response.
I try my hardest not to anthropomorphize these models, so pardon this comparison, but in fairness, even with our human wetware memory the average dev is rarely able to write flawless code without the need for any revisions on their first try.
If we get a more efficient model of comparable quality to GPT-4, adding a line to the frontend to request a second pass on all code based request may not be unreasonable and could, in my experience, yield more consistently usable results.
Considering how quickly OpenAI released gpt-3.5-turbo, I am hopeful that we will see such a development soon, though I currently do not have personal access to the GPT-4 API, so maybe that could be made more accessible first.
https://github.com/knowsuchagency/llmo
I'm really excited to try out aider, thanks for making it!