Training ChatGPT to Code to Your Preferences
Image ceated by Mike Kavis using chatGPT and MidJourney

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).

No alt text provided for this image
Training ChatGPT4 to code like me


ChatGPT reads this and acknowledges that it has learned my preferred style and even shows me a coding example to confirm.

No alt text provided for this image
AI Engine is now trained to my preferences


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.

No alt text provided for this image
Code without training

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?

No alt text provided for this image
Adding test harnesses to code
No alt text provided for this image
Create test data

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?

No alt text provided for this image
Test automation


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.

No alt text provided for this image
Good class on prompt engineering for chatGPT
Yogendrasinh Rajput

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.

回复
Don Chartier

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!

Bob Hersch

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!

回复
Charlie Olson

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.

要查看或添加评论,请登录

Mike Kavis的更多文章

  • The Executive’s Guide to Gen AI

    The Executive’s Guide to Gen AI

    Generative AI is coming to the enterprise. Are you ready? Imagine an engineer sitting with a product owner as the…

    6 条评论
  • AWS is all in on Gen AI

    AWS is all in on Gen AI

    On Tuesday, AWS kicked off its annual conference in Las Vegas and AWS CEO Adam Selipsky's keynote focused exclusively…

    1 条评论
  • Everyone is focused on Resiliency, but what does it really mean?

    Everyone is focused on Resiliency, but what does it really mean?

    I have been working on cloud computing since the early days when AWS had about a dozen services. I have seen the trends…

  • Developers should be flocking to ChatGPT not running from it

    Developers should be flocking to ChatGPT not running from it

    Artifical Intelligence (AI) is getting a lot of press these days and one utility, ChatGPT, is probably getting the most…

    8 条评论
  • AWS Continues to re:Invent Cloud Computing

    AWS Continues to re:Invent Cloud Computing

    Andy Jassy took center stage Tuesday for Amazon Web Services (AWS) annual and first ever virtual re:Invent conference…

    7 条评论
  • Cloud Adoption is Hard

    Cloud Adoption is Hard

    I am a few weeks away from my final draft of my upcoming book "Accelerating Cloud Adoption: Optimizing the Enterprise…

    13 条评论
  • DevOps and the Next Bottleneck: Architecture

    DevOps and the Next Bottleneck: Architecture

    If you have read any of my articles over the years you will know that I subscribe to the definitions of DevOps that…

    10 条评论
  • Advice to my 19-year-old technologist self

    Advice to my 19-year-old technologist self

    Today is another busy day in the life of my long IT career. The day consists of a slew of meetings, a podcast, and then…

    18 条评论
  • Have we entered the golden age of infrastructure?

    Have we entered the golden age of infrastructure?

    There’s never been a better time to be in infrastructure. My developer roots go way back but my journey to the cloud…

    3 条评论
  • The Cloud’s Lock-in vs. Agility Trade-off

    The Cloud’s Lock-in vs. Agility Trade-off

    Many enterprises have the proverbial bad taste in their mouths from years of vendor lock-in on mainframes and database…

社区洞察

其他会员也浏览了