Training ChatGPT to Code to Your Preferences
I recently wrote an article about my POV on ChatGPT and its impact to developers. In this post I want to share the concept of training the AI engine to code to your preferences. In my previous experiments with chatGPT, I would prompt it to create some code and the code that came back was very simple and to the point, but not necessarily the way I would write code. I would later ask it to comment the code, refactor it, add test harnesses and many other things. If you are just experimenting, these additional tasks may be overkill. But if your goal is to create working code that is maintainable and testable, you can train the AI engine to give you code exactly to your specifications right out of the gates.
So here is an example of training the chatGPT to code like you, for better or worse. I first created a Google doc to store these guidelines so I can use them later and modify as needed in the future. I simply cut and pasted the preferences from that document to train the AI engine (Disclaimer: I am not endorsing any of these standards. This is simply an example).
ChatGPT reads this and acknowledges that it has learned my preferred style and even shows me a coding example to confirm.
If I was doing web or mobile development I could add more preferences, standards or styles related to that type of development. If I was a big Java developer, I could add a ton of Java specific recommendations. You get the point. Then I asked it what the code would have looked like if I had not trained it.
This is perfectly good code, just not to my standards. If I am just experimenting, less is better. But if my goal is to eventually get to production quality code that is readable and easy to maintain, I might want to train the engine upfront as opposed to adding that all in later.
Let's say I am far along and ready to start my testing. I am lazy so why not have ChatGPT create the tests and test data for me?
领英推荐
Not only did it create me the test data but it showed me how to use it with the existing code we have been working on. This may seem trivial because there is only two fields but imagine generating complex and large datasets that have different record types like header, body, summary records, etc.
Being the lazy developer I am, why not ask for automated tests?
Summary
You can see from the content above that building working code with chatGPT is an iterative process. You can pretrain the AI to build more robust code that meets your style, preferences and requirements. The key take away is chatGPT is not going to create code in the manner that you prefer unless you tell it to.
The working code you get from chatGPT is only as good as your ability to prompt the AI engine for quality code. No, chatGPT isn't going to take your job away. But if you don't learn the basics of prompt engineering, someone else might.
The following is a very helpful short class on building Python apps using ChatGPT. I highly recommend it if you are new to ChatGPT.
Software Engineer, Founder
2 个月In over two decades of programming, we've learned from our (and others') blunders. We ignored ISO standards unless a customer demanded them. Now, as bots take over coding, ISO standards make a great prompt! Bet the standard creators never saw this coming.
Technology Adoption Professional. Former VP, Microsoft Technology Services Practice at Deloitte Consulting
1 年I don't code (that's a good thing for humanity), but this explanation was very helpful for understanding ChatGPT's potential regarding coding and other tasks. Thank you!
US Strategy & Technology— Partner, Deloitte | Formerly US Ecosystems & Alliances Leader & Global DMTSP Leader (Deloitte's Microsoft Technology Services Practice)
1 年Thank you Myke - this is very comprehensive and helpful!
Managing Director at Deloitte Consulting focusing on Modern Workplace and Cloud Engineering technologies
1 年Mike, I love how you break down the seemingly difficult or even impossible into practical and straight forward advice.