I’ve been using GPT-4 and GPT-4o lately for generating and modifying code, but I often encounter inefficiencies, especially when the model regenerates large sections of code for minor changes.
I’m looking for tips on:
Prompting ChatGPT to make specific changes without rewriting the entire file.
Best practices for iterative development with ChatGPT.
Tools or plugins that enhance code modification efficiency with ChatGPT.
I wrote a project refactoring agent called Quanta Agent, based on Langchain and with a Streamlit chat interface.
It uses a feature called Named Blocks for solving this. It lets you identify sections in your code which you can then ask questions about, or ask the AI to even make updates to and it edits those named blocks in your project.
The agent can also directly edit stuff not in any named blocks too if you want.
Great, I’m happy to answer questions about the project or collaborate to improve the project, or discuss other approaches.
One improvement I think I will make eventually is to use XML Tags in the templates to enclose various chunks of instructions, but the way I have it now does work well afaik.
As for tools and plugins for code modification, I can offer two open source solutions.
The Co-Developer GPT engine is a local server + a GPT which you can create in ChatGPT that gives ChatGPT functions to list, search, read and modify files in the directory the local server is started, and run local actions you configure, such as running a build. Thus you can employ it as an interesting mixture of junior and senior developer, read and discuss your code and have it change it by it self, even tell it to run the build and fix things until it works. That has limits, of course, but can be quite helpful and relieves you from copy and pasting code into ChatGPT.
Then I developed AI based code generation pipeline to systematically employ AI code generation in my projects. It’s a command line tool (or alternatively a Java framework) where you give prompt files, input files and an output file on each invocation, and the AI is run to (re-)generate the output file only if a prompt or input file has changed since the last run.
Under the hood: the GPT engine has functions to overwrite a file or do a multi line search and replace in the file. (I experimented with other operations a while ago, but didn’t have much success.) The aigenpipeline has the AI overwrite the output file in one go; if you want to have it incrementially changed the output file is also given as input to the AI (normally the ChatGPT chat completion API) and the AI is instructed to make only minor modifications, which seems to work quite well. I use a conversation pattern I call “put it into the AI’s mouth” that nicely separates data and instructions and seems to work very well.