Blog

ChatGPT – AI at Its Finest

Category
Software development
ChatGPT – AI at Its Finest

As you already know, an AI-powered bot has recently emerged on the scene, named ChatGPT, and it is worth paying attention to. Even for those who are not particularly interested in artificial intelligence.

What is ChatGPT?

ChatGPT is an artificial intelligence software developed by OpenAI research laboratory where people can ask questions, and the software will answer their questions based on context and relevance.

asking chatgpt questions

ChatGPT is a large language model designed to understand and respond to natural language. It answers almost any question you have because it’s trained through a wide variety of texts, books, articles, and websites. People are utilizing the capabilities of ChatGPT beyond casual conversations and using it for various purposes. This includes writing articles, academic papers, job applications, and even programming code. It proved itself as a useful tool in assisting us in completing our tasks more efficiently.

In this blog, I want to explore key capabilities of ChatGPT, like answering questions and performing programming tasks.

How does ChatGPT it work?

It’s a state-of-the-art natural language processing (NLP) model, a variation of the widely recognized GPT-3 model which has been created by fine-tuning the GPT-3 algorithm on a huge amount of text data, enabling it to produce responses that mimic human-like language.

This training process allows ChatGPT to generate answers relevant to the input it receives.

It’s a cutting-edge NLP model that differs from the conventional ones. It does not require human-made rules or manually tagged data to function. Instead, it adopts a neural network setup and utilizes unsupervised learning to generate answers.

This allows it to learn how to reply without being explicitly instructed on the correct answer, making it a formidable tool for diverse conversational purposes.

Using ChatGPT is very simple. You only have to type a question, and ChatGPT will generate appropriate responses in a conversational setting, allowing you to learn new things or have fun conversations. It can write essays on a range of subjects, from straightforward to intricate topics.

Using ChatGPT in programming

As already mentioned, one of the most interesting features of this software is that it can produce code. Let’s play with a few examples.

Example 1

A very common thing in many programming languages that developers forget is opening a file and writing to it. So let’s try in Java:

chatgpt ai tool

Apart from the code itself, ChatGPT wrote a short explanation below. Besides just generating code, ChatGPT has enough capability to refactor some code. Let’s give it a code where some improvements could be done, like:

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
public class WriteFile {
    public static void main(String[] args) {
        try {
            File file = new File("example.txt");
            if (1 == 0) {
                System.out.println("This will never be reached");
            }
            String string = null;
            System.out.println("String length is " + string.length()); // NullPointerException
            PrintWriter writer = new PrintWriter(file);
            writer.println("Hello, this is a sample text.");
            System.out.println("File written successfully!");
        } catch (IOException e) {
            System.out.println("An error occurred.");
            e.printStackTrace();
        }
    }
}

It’s pretty much the same code in Java for writing a file as above, but with a few additions. Firstly, a condition that will never be reached is added. After that, there is a string with null value, so the next line will throw a NullPointerException. Also, writer.close() is removed, which is dangerous because closing a writer deallocates any value in it or any associated resources. Let’s see what ChatGPT suggests for improvements.

chat gpt

ChatGPT fixed the bugs and gave explanations about the changes. Also, the generated code is not the same as the one first generated. In this response, the writer object is ensured to be closed with a try-with-resources block, which is also an option for closing objects that implement a Closeable interface.

Example 2

In this short period of using ChatGPT, I also got the impression that it is very accurate for some CI/CD tools. Many developers who don’t use these tools every day spend a lot of time googling and copy-pasting with the sole aim of getting it to do what they need without knowing what’s going on behind the scenes.

ChatGPT might be a good partner in these actions because besides just providing the result, it also gives some very useful explanations. 

In Notch, most projects are Java-based using Spring framework so in the example 2, I want to attempt to build a Docker image for a Spring Boot project and publish the image to Docker Hub.  

In this solution, ChatGPT provided a Dockerfile which uses a multi-stage build that finally ends with an Alpine image. An Alpine image is a lightweight version of the base image that is built specifically for containers. It is designed to be small, fast, and secure. It typically includes only the essential components needed to run a specific application, making it a popular choice for the use in containerized environments because of low resource usage.

The next step is to produce a workflow in GitHub Actions that will publish the image to Docker Hub on every new release created.

The action will be triggered every time a new release is published, automatically a new version of the application will be published to Docker Hub, so it can be available on an official container image repository. 

The bottom line is that ChatGPT can do powerful things and have a conversation with you about your code. Of course, many programming tasks can be performed, but that will be left to the reader for entertainment.

What are the limitations of ChatGPT?

One of the limitations of ChatGPT is that it is a large and complex model, which makes it resource-intensive to run and that is also the reason why the service is very often down. The use of ChatGPT in real-time applications such as chatbots can be challenging due to its requirement for longer processing times, making it difficult to generate quick responses in fast-paced environments. 

ChatGPT, although a remarkable model, does have certain limitations. One of them is that it is a generative model, meaning that its answers may not always be accurate for specific questions.

On occasion, the produced replies may be off-topic or nonsensical because of the absence of a solid source of truth in its reinforcement learning training. This can pose challenges in using it for some applications.

Another limitation of ChatGPT, like all NLP models, is its dependence on the data it was trained on. Suppose the data it was exposed to is limited in quantity and diversity. In that case, the model may struggle to generate accurate responses for inputs that fall outside the scope of its training data. 

Is ChatGPT better than Google?

Obtaining answers to questions from a computer is useful, and ChatGPT has proven effective in delivering accurate responses. 

Google is known for providing suggested answers and relevant website links in response to questions. However, ChatGPT’s answers tend to be more comprehensive than Google’s suggestions. This might make it seem like ChatGPT is a worthy competitor. Nevertheless, it is crucial to exercise caution when relying on ChatGPT for information. Just like with Google or other information sources.

To ensure accuracy, it’s always advisable to verify the information from primary sources before relying on it.

Verifying the accuracy of ChatGPT’s answers can be a bit challenging. This is because it only provides raw text without any links or references. However, it can still be useful and may spark new ideas. You may not find a model like ChatGPT in Google’s search results. However, Google has already developed large language models and utilizes AI extensively in its search function.

Latterly, many extensions, and libraries related to ChatGPT are developed. One good usage option would be using an extension in your browser that displays ChatGPT answers simultaneously with the Google response. For example, in Google Chrome.

Conclusion

ChatGPT is a powerful tool that can assist with a wide range of tasks. This includes answering questions and assisting with programming. Its ability to continuously learn and improve means and becomes more accurate and helpful over time, making it an invaluable resource for people in various fields. 

In the end, there is a fun fact that it can also write a blog like this one, including the title.

chatgpt use cases

Which brings us to the question: did I write this blog myself, or did ChatGPT write it? We’ll never know.

CONTACT US

Exceptional ideas need experienced partners.