ChatGPT – The next step in AI

Like usually I was scrolling the news and looking out for any new interesting stuff. I mainly just read news about new tech, especially regarding computer science, AI, space exploration, rockets and computer hardware. And yesterday I came across ChatGPT – the next version of the GPT model (Generative Pre-trained Transformer) preceded by the GPT-3 model, which was already very advanced and was able to do some quite amazing things.
GPT is a language model that produces human-like text and has the ability to, given an initial text as prompt, produce text that continues the input text.

This means the model can be asked questions and answers them, given a piece of wrong code and find the potential problems in it and it also remembers the past actions. It feels almost like we are talking to a human.

So ChatGPT is a large improvement of the previous GPT-3 model. It is based on the GPT-3.5 model. And let me tell you, this thing is pretty amazing. You can try it yourself as long as there is still beta access available to public for testing on the OpenAI’s site. For now it is still free, so give it a try, since in the future a pricing plan will probably be introduced.

I tried a lot of things, asking it to write code, a poem, an essay, asking it all sorts of different questions and below are some examples of its responses.


Help me this code doesn’t work!

One of the things this model can do is to help you analyze your code and what might be wrong with it. So what I did is I intentionally left out some lines of code and then asked the model what might be wrong. I used pretty specific code in this case – I tried to obtain the CPU stepping number via C++ inline assembly and left out a line of code, as well as incorrectly tried to obtain the number itself.

PROMPT

I have a piece of code in C++ here where I try to obtain the CPU stepping number, but the code does not work. Do you know what is wrong?

uint32 CPUM::getSteppingNumber() {
uint32 data;
__asm__(“mov $0x1, %eax\n\t”);
__asm__(“cpuid\n\t”);
return steppingNumber;
}

ANSWER

There are a few issues with this code. First, it uses inline assembly, which is not portable and may not work on all platforms. Second, it uses the cpuid instruction to obtain the CPU stepping number, but this instruction returns the stepping number in the least significant nibble of the eax register, not the eax register itself. You need to mask off the other bits to obtain the stepping number. Third, the code does not save the value returned by the cpuid instruction, so the return value will be undefined.

Here is a revised version of the code that uses the cpuid instruction correctly and does not use inline assembly:

#include <cstdint>

uint32_t getSteppingNumber() {
    uint32_t data;

    // Use the cpuid instruction to obtain the stepping number.
    asm volatile("cpuid" : "=a" (data) : "a" (1) : "ebx", "ecx", "edx");

    // Mask off the other bits to obtain the stepping number.
    uint8_t steppingNumber = data & 15;

    return steppingNumber;
}

Note that this code still uses the cpuid instruction, which is not standard C++ and may not be supported on all platforms. If you need to write portable code, you should use the __get_cpuid intrinsic, which is available on some compilers and platforms.

For example, here is how you could use the __get_cpuid intrinsic to obtain the CPU stepping number:

#include <cstdint>

uint32_t getSteppingNumber() {
    uint32_t eax, ebx, ecx, edx;

    // Use the __get_cpuid intrinsic to obtain the CPUID data.
    __get_cpuid(1, &eax, &ebx, &ecx, &edx);

    // Mask off the other bits to obtain the stepping number.
    uint8_t steppingNumber = eax & 15;

    return steppingNumber;
}

CONCLUSION

I got a pretty satisfactory answer. It warned me of the fact that the code should probably not use inline assembly. This is probably a good idea, since things can be done in a better way using just the C++ intrinsics. It also provided an alternative solution to my problem – which I tested and it works! All I had to to was to include the cpuid.h header.


I am trying to make a program

This time I decided to ask the model to write me a program.

PROMPT

Write a python snake game.

ANSWER

Here is a simple implementation of a snake game in Python. It uses the curses library to create a terminal-based user interface, and it uses the arrow keys to control the snake.

import curses
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN
from random import randint

curses.initscr()
win = curses.newwin(20, 60, 0, 0)
win.keypad(1)
curses.noecho()
curses.curs_set(0)
win.border(0)
win.nodelay(1)

key = KEY_RIGHT                                                   
score = 0

snake = [[4,10], [4,9], [4,8]]                                    
food = [10,20]                                                    

win.addch(food[0], food[1], '*')                                  

while key != 27:                                                  
    win.border(0)
    win.addstr(0, 2, 'Score : ' + str(score) + ' ')                
    win.addstr(0, 27, ' SNAKE ')                                  
    win.timeout(150 - (len(snake)/5 + len(snake)/10)%120)         
    
    prevKey = key                                                 
    event = win.getch()
    key = key if event == -1 else event 

    if key == ord(' '):                                           
        key = -1                                                  
        while key != ord(' '):
            key = win.getch()
        key = prevKey
        continue

    if key not in [KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN, 27]:    
        key = prevKey

    snake.insert(0, [snake[0][0] + (key == KEY_DOWN and 1) + (key == KEY_UP and -1), snake[0][1] + (key == KEY_LEFT and -1) + (key == KEY_RIGHT and 1)])

    if snake[0][0] == 0: snake[0][0] = 18
    if snake[0][1] == 0: snake[0][1] = 58
    if snake[0][0] == 19: snake[0][0] = 1
    if snake[0][1] == 59: snake[0][1] = 1

    if snake[0] in snake[1:]: break

    if snake[0] == food:                                           
        food = []
        score += 1
        while food == []:
            food = [randint(1, 18), randint(1, 58)]                
            if food in snake: food = []
        win.addch(food[0], food[1], '*')
    else:    
        last = snake.pop()                                         
        win.addch(last[0], last[1], ' ')
    win.addch(snake[0][0], snake[0][1], '#')

curses.endwin()
print("\nScore - " + str(score))

To run this code, you will need to have the curses library installed on your system. You can install it using pip

CONCLUSION

Well, all I am going to say is that I am very impressed. I was provided with all the information I need and the code worked almost immediately. After I installed the curses library – which I was also instructed to – I just had to cast a float to an integer in the code and program worked! I got a basic snake game, as I requested. There was no border collision detection, but since I didn’t explicitly ask for it, I think this is perfectly fine. The game otherwise works as expected. Below is a gif showing how the game works!

What I tried after that is adjusting the instructions I have give the model a little bit and tried telling it to add a combination of buttons for exiting the game as well as add border collision detection. It did just that.

Unfortunately the model output size is limited, so I was not given the whole code, just the beginning of it. However, I am pretty certain that if the model completed the whole code it would have probably worked.


Make an HTML server

Next I asked it to make an HTML server that displays the current weather in Tokyo, Japan.

PROMPT

Make an HTML server in python that displays the current weather in Tokyo, Japan.

ANSWER

Here is a simple implementation of a web server in Python that serves an HTML page that displays the current weather in Tokyo, Japan. It uses the requests module to retrieve the current weather data from an online weather API, and it uses the BaseHTTPServer module to create the server and handle HTTP requests and responses.

import requests
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler

class RequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()

        response = requests.get('http://api.openweathermap.org/data/2.5/weather?q=Tokyo,jp&appid=<API KEY>')
        weather_data = response.json()

        temperature = weather_data['main']['temp']
        weather_description = weather_data['weather'][0]['description']

        self.wfile.write('<html><body><h1>Current weather in Tokyo</h1>')
        self.wfile.write('<p>Temperature: ' + str(temperature) + '</p>')
        self.wfile.write('<p>Weather: ' + weather_description + '</p>')
        self.wfile.write('</body></html>')

server = HTTPServer(('localhost', 8080), RequestHandler)
server.serve_forever()

To run this code, you will need to have the BaseHTTPServer and requests modules installed on your system. You can install these modules using pip:

pip install requests

You will also need to obtain an API key from the OpenWeatherMap API to be able to access the current weather data. You can sign up for a free API key on the OpenWeatherMap website.

To start the server, simply run the code using the python interpreter. The server will listen on port 8080 on the localhost interface, so you can access it by visiting http://localhost:8080 in your web browser. The server will retrieve the current weather data for Tokyo, Japan and display it on the HTML page.

CONCLUSION

Yet again I got the code and all the information I need, as well as all the instructions on how the code works, how to run it, how to open a website. It is almost like talking to a human – everything is explained, I am not just given the code and that’s it. This is honestly the part that really amazes me – the fact that it offers much more than just the code itself.

However I did come across a little problem. The module BaseHTTPServer was moved into the http.server module, so all I had to do was to replace the BaseHTTPServer with the http.server library.

Here is how the server works after installing the requests, http.server module and obtaining the OpenWeatherMap API key.

This time however everything did not work perfectly well. I think where the program messed up is with the JSON structure of the API request. Still, the website itself is working if I replace the JSON call with a simple HTML site. I also needed to change the input data of the write function to be bytes – which required me to just add a b at the start of the string. After that the website worked!

So yeah, the code was not perfect, but it would have given me a great base to work with. And all I had to do to make it work (albeit without the weather functionality) was to change one little thing in the code – incorrect data type for the write function.


I can write an essay!

ChatGPT can do much more than just analyze and write code. It can also form content based on out request. It can write a story or a poem, it can write an essay or an article. It can basically do a lot! Here are some examples of such functionality. I have asked the model to write me an essay comparing fusion an fission as a source of energy, then asked it to write me a song about rockets and planets as well as asked it to write a story about a cat who got lost in a forest. Pretty random, but this was my aim, to see what it could come up with.

Fusion vs. fission

PROMPT

Write an essay comparing fusion and fission as the source of energy.

ANSWER

Fusion and fission are both nuclear reactions that involve the rearrangement of atomic nuclei and the release of large amounts of energy. While these reactions are similar in some ways, they also have significant differences that make them suitable for different purposes.

Fusion is the process of combining two atomic nuclei to form a single, heavier nucleus. This process releases a large amount of energy in the form of heat and light. Fusion reactions occur naturally in stars, where they provide the energy that powers the star’s luminosity.

Fission, on the other hand, is the process of splitting a single atomic nucleus into two or more smaller nuclei. This process also releases a large amount of energy, but in the form of kinetic energy rather than heat and light. Fission reactions are used in nuclear power plants to generate electricity.

One of the key differences between fusion and fission is the type of fuel they require. Fusion reactions can be powered by a variety of light elements, such as hydrogen and helium, which are abundant in the universe. Fission reactions, on the other hand, require heavy elements, such as uranium and plutonium, which are much less common.

Another significant difference between fusion and fission is the amount of energy they release. Fusion reactions release much more energy per unit of mass than fission reactions, making them potentially much more efficient as a source of energy. However, achieving and maintaining the extremely high temperatures and pressures necessary for fusion reactions is difficult, and no one has yet been able to create a fusion reactor that produces more energy than it consumes.

In terms of safety, fusion reactions are generally considered to be safer than fission reactions. Because fusion reactions require such high temperatures and pressures to occur, they cannot easily go out of control. Fission reactions, on the other hand, can potentially release dangerous levels of radiation if not properly controlled.

Overall, fusion and fission are both powerful sources of energy, but they have different strengths and weaknesses. Fusion has the potential to be more efficient and safer than fission, but achieving practical fusion reactions remains a significant challenge. Fission, on the other hand, is a well-established technology that is currently used to generate electricity, but it has significant safety concerns.

CONCLUSION

I think the essay was written nicely. It has an introduction, presenting the topics and then continues to explain each individual topic further. After that it introduces three main differences between the technologies and ends the essay with a summary. I am not an expert in this field but I didn’t notice anything wrong when it comes to the content itself. I give it a pass.


A song about rockets and planets

PROMPT

Write a poem about rockets and planets.

ANSWER

Rockets roar into the sky
Leaving Earth behind
On a journey to the stars
And the wonders that we’ll find

Planets loom before us
Mysterious and vast
Each one with its own beauty
A wonder to be cast

We’ll explore new horizons
And push the boundaries wide
Discovering the secrets
Of the universe inside

With every step we take
We’ll learn a little more
About the world around us
And the endlessness of space and time

So let us hold our heads up high
And reach for the stars
For the journey of a lifetime
Is just beginning, and we’ll go far.

CONCLUSION

Yet again, I am quite amazed by the fact that this thing can write code and at the same time write a poem that is coherent, looks legit and reads pretty well.


A story about a cat who got lost in the forest

PROMPT

Write a story about a cat who got lost in the forest.

ANSWER

It was a beautiful autumn day when Fluffy, the curious little cat, wandered out into the forest. She had always loved exploring the great outdoors, and today was no exception. She padded through the leaves, chasing after birds and squirrels, her tail held high.

As the day wore on, Fluffy became increasingly lost. She had wandered further and further from home, and now she had no idea how to get back. She tried to retrace her steps, but the forest was a confusing maze of trees and underbrush, and she soon found herself completely turned around.

As night began to fall, Fluffy became scared. She had never been out in the forest at night before, and the strange noises and shadows were overwhelming. She tried to curl up and sleep, but the cold and the dampness of the forest floor made it impossible to get comfortable.

As the hours passed, Fluffy grew hungrier and thirstier. She had not eaten or drunk anything since early that morning, and now she was starting to feel weak and sick. She tried to hunt for mice or rabbits, but the forest was too dark and she was too inexperienced to catch anything.

Just when Fluffy was about to give up hope, she heard a familiar sound in the distance. It was the sound of her owner calling her name! She jumped to her feet and began to run towards the sound, meowing as loudly as she could. Finally, after what felt like an eternity, she emerged from the forest, exhausted but overjoyed, into the safety of her owner’s arms.

From that day on, Fluffy never wandered too far from home again. She had learned her lesson, and she was grateful to be safe and sound. And she never forgot the adventure she had in the forest, and the thrill of finally finding her way back home.

CONCLUSION

A cute short story. I don’t have much to more to say, the story looks interesting and creative. However one cool thing that can be done with the model is that after it has given an answer we can tell it to change things. For example I told it to change the cat’s name to Oscar and told it to make a different ending. It did just that. It changed the cat’s name to Oscar and changed the ending. The story took a turn after the cat got lost and instead of just finding it’s way back home, the cat find a cabin and spends some time there.

ALTERNATIVE STORY

It was a beautiful autumn day when Oscar, the curious little cat, wandered out into the forest. He had always loved exploring the great outdoors, and today was no exception. He padded through the leaves, chasing after birds and squirrels, his tail held high.

As the day wore on, Oscar became increasingly lost. He had wandered further and further from home, and now he had no idea how to get back. He tried to retrace his steps, but the forest was a confusing maze of trees and underbrush, and he soon found himself completely turned around.

As night began to fall, Oscar became scared. He had never been out in the forest at night before, and the strange noises and shadows were overwhelming. He tried to curl up and sleep, but the cold and the dampness of the forest floor made it impossible to get comfortable.

As the hours passed, Oscar grew hungrier and thirstier. He had not eaten or drunk anything since early that morning, and now he was starting to feel weak and sick. He tried to hunt for mice or rabbits, but the forest was too dark and he was too inexperienced to catch anything.

Just when Oscar was about to give up hope, he spotted a small cabin in the distance. He could see a light shining through the window, and he could hear the sound of a fire crackling inside. He ran towards the cabin as fast as he could, hoping to find safety and warmth inside.

To his relief, the cabin was empty. He slipped inside and curled up in front of the fire, feeling grateful for the shelter and the warmth. He fell asleep, dreaming of home and his owner, and hoping to be rescued soon.

The next morning, Oscar was woken by the sound of someone approaching the cabin. He ran to the door, meowing as loudly as he could, and to his joy he saw his owner standing outside! They had been searching for him all night, and now they were finally reunited.

Oscar was overjoyed to be back home, and he promised himself that he would never wander off into the forest again. He had learned his lesson the hard way, and he was grateful to be safe and sound once more. And he never forgot the adventure he had in the forest, and the thrill of finally finding his way back home.


More examples

Here are some more examples of the things that GPT can do.

Answering questions

How to open a can

What is an aerospike engine

Movies similar to Breaking Bad

I don’t understand this code


Conclusion

There is a lot more to this. ChatGPT can do a lot of different things. It can help you with programming, answer your questions and a lot more. I just tested some examples and most of the time I got great answers! The code doesn’t always work perfectly, but you usually just have to change a thing or two. Also, you can ask the model much more specific questions and it will answer them well. It’s like Google combined with a human. Amazing.

3 thoughts on “ChatGPT – The next step in AI”

    1. Typically, I keep up with the latest news in computer hardware by reading Google News on my phone and occasionally browsing Twitter/X. However, I haven’t been closely following recent innovations in that area lately, so nothing specific comes to mind right now.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top