ChatGPT | I am speechless

ChatGPT | I am speechless

December 5, 2022

Artificial Intelligence
Programming
Coding

Recently open AI released chatGPT, and since then my Twitter feed has been filled with chatGPT’s screenshots. People ask different types of questions in various industries, Coding, Content writing, Script writing, and some mind-boggling questions just to play with the AI and how smart it can be.

The moment I heard of it, I started testing it in a coding context and was blown by it. In my last blog about Github Co-pilot, I mentioned it will just help people with syntax and general stuff and not take away any jobs. I need to take that statement back, I did underestimate openAI. Here is what happened

chatGPT can code better than you

Yes, you heard it right it can code better than you. I know I might get some heat for what I just said, but stay with me on this.

Converting code from one language to another.

I know you might say there are thousands of websites that can do that like kalkicode.com. But those websites have limitations you can give them a snippet of code and they can convert if you give them your whole project file and tell them to convert you will end up having a ton of bugs and some conversions might not even make sense. Here is what chatGPT did

I asked it to convert this PHP code to Vue.js

          <!DOCTYPE html>
<html>
<head>
  <title>Contact Form</title>
</head>
<body>
  <h1>Contact Form</h1>
  <form action="" method="post">
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" />
    <br />
    <label for="email">Email:</label>
    <input type="email" id="email" name="email" />
    <br />
    <label for="phone">Phone:</label>
    <input type="tel" id="phone" name="phone" />
    <br />
    <label for="message">Message:</label>
    <br />
    <textarea id="message" name="message" rows="5" cols="40"></textarea>
    <br />
    <input type="submit" name="submit" value="Submit" />
  </form>
  <?php
    // Check if the form has been submitted
    if (isset($_POST['submit'])) {
      // Retrieve the form data
      $name = $_POST['name'];
      $email = $_POST['email'];
      $phone = $_POST['phone'];
      $message = $_POST['message'];

      // Print the submitted data to the page
      echo "<h2>You submitted the following information:</h2>";
      echo "<p>Name: $name</p>";
      echo "<p>Email: $email</p>";
      echo "<p>Phone: $phone</p>";
      echo "<p>Message: $message</p>";
    }
  ?>
</body>
</html>

        

Here is how chatGPT did it

          <div id="app">
  <h1>Contact Form</h1>
  <form>
    <label for="name">Name:</label>
    <input type="text" v-model="name" />
    <br />
    <label for="email">Email:</label>
    <input type="email" v-model="email" />
    <br />
    <label for="phone">Phone:</label>
    <input type="tel" v-model="phone" />
    <br />
    <label for="message">Message:</label>
    <br />
    <textarea v-model="message" rows="5" cols="40"></textarea>
    <br />
    <input type="submit" v-on:click="submitForm" value="Submit" />
  </form>
  <div v-if="submitted">
    <h2>You submitted the following information:</h2>
    <p>Name: {{ name }}</p>
    <p>Email: {{ email }}</p>
    <p>Phone: {{ phone }}</p>
    <p>Message: {{ message }}</p>
  </div>
</div>

<script>
  new Vue({
    el: '#app',
    data: {
      name: '',
      email: '',
      phone: '',
      message: '',
      submitted: false
    },
    methods: {
      submitForm() {
        this.submitted = true;
      }
    }
  });
</script>

        

If you are a developer who has a good knowledge of both will know, this is more than 95% accuracy in code. It is not just converting your syntax from php to vue, In fact, it understands the context of what you are trying to do with that. This was a very basic example, I had tried to put a production application Vue.js file and asked to convert it to React.js and it really stunned me.

Simplify you code

If you can just paste a code from anywhere and tell chatGPT to simplify it. It will simplify the code for you and not just that. Alongside it will explain, what you have used why it is not very efficient, and suggest using an efficient method. Here is what I did

I asked chat GPT to simplify this code

          var searchInsert = function(nums, target) {
    let result = 0;
      for(let i = 0; i <= nums.length ; i++) { 
        if(target == nums[i]) { 
          result = i;
        } else { 
          if(nums[i] < target) { 
            result  = i + 1 
          } 
        }
      }
   return result;
}; 

        

Here is what it replied

ChatGPT | I am speechless

Firstly, It has recognized what I am trying to do with this code and has given a short summary of similar use cases of the code. Secondly, It has simplified the code as you can see. In the end, It is explaining me, what changes it has made and why is it efficient. As you can see what level it is to understand the code and whom we will be competing with in the coming years. Again this was a very simple example and trust me it is capable of much more.

Solving Leetcode problems

I have thought of just messing with it let's try to give the most challenging DSA questions on Leetcode which I think Developers take days to solve. I took a hard problem from Leetcode and directly pasted it in chatGPT here is what happened

Here is the question

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.

The overall run time complexity should be O(log (m+n)).

This is a Hard problem from Leetcode and let's see what chatGPT replied.

ChatGPT | I am speechless

Let’s see what is happening here, Firstly It has given a short summary of what the problem is and explains the thought process of how you can solve it. As the code, you can see it has solved the problem. In the end, it has been mentioned, this is not the most efficient solution to this problem and has provided time complexity.

The best part of it, If you give it the constraints of the problem and ask it to provide the most efficient solution, It will blow your mind.

Lifesaver in solving bugs

Say you are stuck in some problem for hours and not able to figure out a solution. If you paste the same in chatGPT and just write precisely what you are trying to do and why is it not working. Here is what I asked.

Why person object is getting changed If I am changing person1?

          let person = {
   name: 'kamran',
  age: 26
}

let person1 = person 

person1.name = 'john';

console.log(`person`, person)
console.log(`person1`, person1)

        

Here is how chatGPT replied

ChatGPT | I am speechless

Doesn't it feel like you are talking to a person who is explaining to you what is it that you are doing wrong? It knows what you are trying to do and it explained what have you done wrong and how can you make it right.

This was a pretty simple example, I have tried one on one with this and given a complex problem and asked how can I solve this without using this plugin or package and it has given me an alternative.

Final Thoughts

I have always thought code will be the last thing to automate as it is tough and many people find it so hard to do. But I think we have all forgotten one thing about code which is defined output, Coding has a defined output so AI can give you accurate results because it can predict what you are trying to accomplish. This I believe won't be in the case of Design, Video, or entertainment where you don't have a defined output, and the likeness of the same is very subjective for the user.

In this blog above I have only spoken about coding in chatGPT, But some of the screenshots I have seen on Twitter where people are writing poems, scripts, and even some specific personal questions, and the answers to those were phenomenal. To be honest, this AI has really scared me about my job and even others, people who are at the bottom of the pyramid are gonna be jobless if they don't adapt to this.

Now we can say there will be a time when AI will be able to create an Enterprise level application with just 2-3 openAI operators and many companies will adopt this like crazy. This tech is massively destructive and I am sure people will be using it everywhere from writing emails to blogging (I am using it now while writing this). The possibility of cheating in exams, and Tech interviews might shoot up. With this, I think we have reached the first legit phase of automation in technology.

Here is an extension that I found very useful which is chatGPT answers right at the google search results. https://github.com/wong2/chat-gpt-google-extension