How to use ChatGPT to write code and generate websites

Richard Gao
6 min readDec 10, 2022

--

Recently I’ve been testing out GPT-3 with some free credits to help me code — especially on subjects that I’m just starting to learn about. It’s really great! Here are some things I’ve tried using GPT-3:

  1. Correcting Code
  2. Improving runtime of code
  3. Creating starter templates on popular / well documented tasks such as: Azure Devops, AzureML, ML, Terraform (infrastructure as code), websites in flask
  4. Solving a Linear optimization problem and Bipartite Matchmaking (!!! This really blew my mind)

To make a long story short, I’ll probably be using GPT-3 as a form of glorified search engine / stack overflow / a template builder / learning tool to save time. Although this doesn’t necessarily mean it’ll replace whatever I’m using right now (and you probably shouldn’t query it with company specifc / sensitive information / code / data). It’s great for generating a template and pointing you in the generally correct direction — especially if it’s a popular task. Usually when writing code that you haven’t written before, it might take 2–3 iterations to get it right. This feels like a tool that’ll at least help get rid of the 1st iteration of trying out things when you don’t know exactly what to do / want a quick start vs staring at documentation. It even explains its code which is really awesome. Some down sides include the fact that it won’t get things quite right sometimes and isn’t great at object oriented code unless explicitly asked. Sometimes it’ll even stop short when generating code. Here are some samples I’ve tested out that I found interesting:

Querying an API: “Create a python class that queries the hubspot engagements api”

Correcting my code: “what is wrong with this program?”

def addtwovariables(a,b):
result = a+str(b)
return result

Interestingly it assumes I want to add two strings — it doesn’t assume my mistake is in casting the variable as a string to be a mistake — even though the name of the function is “addtwonumbers”. The next piece of code I gave it has an infinite loop issue — which it correctly identifies:

Dynamic Programming:

“Solve the following with a dynamic program: Given a string s, return the longest palindromic substring in s. Example 1: Input: s = “babad” Output: “bab” Explanation: “aba” is also a valid answer. Example 2: Input: s = “cbbd” Output: “bb” Constraints: 1 <= s.length <= 1000 s consist of only digits and English letters.”

However this solution has poor runtime. Maybe we can improve that?

Dynamic Programming in O(n) time:

This solution beat 97.3% of other solutions in terms of runtime:

Protein folding: (Incomplete but at least gives me a template — also someone please tell me if this at least partially correct because I have no idea)

Stock Portfolio Building: (Incomplete but at least gives me a template)

An interesting thing that came up during this was when I asked it to give me stock picking advice it initially refused. I had to go in a round about way in my wording a bit to get the desired result.

Building Neural Nets: (Incomplete but at least provides a template)

Building AzureML Pipelines:

Building Devops Pipelines:

Infrastructure as Code:

Notice that it keeps the context of my previous queries (I had mentioned loan prediction in a previous azure ml pipeline query).

Linear Optimization:

This one blew me away. Especially considering it took several aspects of the prompt into consideration. It changed the player salaries given their scoring averages, and even knew the different positions in basketball even though I didn’t provide them (despite saying it isn’t connected to the internet?). The only downside is it stopped generating half way. I tried solving a similar prompt with another article I wrote here

I also tried using a different (but well known metric in basketball) to see if it knew how to incorporate that. Unfortunately, it did understand what I was talking about but fell short in implementation.

Matchmaking:

This also blew my mind. Data Analysts/Engineers/Scientists and Programmers main job is to translate business problems into code / results / findings. However GPT is able to take the context of the business problem into account and generate code for you. This can serve as a great option for the afore mentioned roles to consider before starting their implementation.

I also asked it to generate a website based on that prompt: Here’s the results:

Implications:

I have to test GPT-3 more to see its shortcomings. In this article I’m mainly focusing on the things it seems to do well at first glance. I do see it being used as a greater and more robust search engine, however I’m concerned as to the fact that it doesn’t seem to cite its sources. I also foresee somewhat code proficient yet business oriented founders attempting to become one man armies with GPT and starting their own products. Although the success of such ventures remain to be seen. There’s probably a lot of shortcomings I haven’t identified but for now, I think it’s very cool. What are your thoughts?

Edit: I just noticed they have a limitations section on their website which you can find here: https://openai.com/blog/chatgpt/

--

--

Richard Gao

Computer Science and Data Enthusiast | Linkedin: https://www.linkedin.com/in/richard-gao-csecon/ | Shovelling data into the AI engine