How To Use ChatGPT For Programming
How To Use ChatGPT For Programming
The main goal of this thesis was to learn how to use ChatGPT for programming and
create a mobile application project using an AI language assistant as a help tool.
Proper use of ChatGPT in the programmer’s workflow can reduce the time required to
solve certain tasks. The thesis was aimed not only at developing application but at
exploring the potential benefits and limitations of using intelligent chatbot as a devel-
opment tool and figuring out the best ways to use it effectively.
Also, this thesis goes through the basic concepts of ChatGPT and explores different
language models, which are used to build neural conversational models and their ap-
plications.
As a result of this thesis, a basic version of the Task Management application was
developed, which included all the functionalities that were desired. The idea of the
application is to help people to manage daily tasks to save time. Frontend was imple-
mented with the help of React Native library and Authentication was implemented with
the help of Firebase.
The process of creating the prototype went smoothly without any big issues. ChatGPT
was especially helpful for generating code snippets, although the intelligent chatbot
could not always solve problems or errors that came up. But overall, ChatGPT helped
to build mobile application with basic functionality in few days. With experience in Re-
act programming and Firebase Authentication, understanding errors and challenges
became easier. To take full advantage from AI language assistant some knowledge
around programming is required.
The originality of this thesis has been checked using Turnitin Originality Check ser-
vice.
Tiivistelmä
1 Introduction 1
2 Introduction to ChatGPT 2
4 Results 27
5 Conclusion 32
References 34
List of Abbrevations
1 Introduction
The advent of ChatGPT raises important questions about how many people's
lives will change and whether professionals will lose their jobs. The main pur-
pose of the thesis project is to study the use of ChatGPT in programming and to
check the accuracy and correctness of its answers, as well as to understand
how it can simplify the programmer's workflow. The engineering work also ex-
amines the language models used to create neural conversational models and
explores the basic concepts of ChatGPT.
The work first introduces the technologies related to ChatGPT, including its his-
tory of creation and prototypes, and then demonstrates its use in programming
by providing an example of creating a mobile application.
The idea for the engineering job came from Suomen Sijoitutkimus Oy, the com-
pany where I work. The correct use of ChatGPT in a programmer's work can
shorten the time required to solve certain problems and become an indispensa-
ble assistant at work.
chatbot. In chapter 3, the thesis goes through the details of case project, explor-
ing the development process of a mobile application using a conversational AI.
Chapter 4 aims to provide practical insights and best practices for utilizing Chat
GPT for application development.
2 Introduction to ChatGPT
The chapter begins with an overview of artificial intelligence, its definition, and
key technique such as natural language processing. This is followed by an ex-
planation of language models, including their purpose, structure, and types. Af-
ter that, chapter introduces the history of ChatGPT, its creators, the process of
development and fundamental principles of artificial language model.
Artificial intelligence has permeated every aspect of modern life and continues
to gain interest. AI refers to the simulation of human intelligence in machines
and is based on the principle that human intelligence can be defined in a way
that allows machines to imitate it and perform tasks. (Frankenfield 2022). It can
be a manifestation of some kind of creative ability, a tendency to reason, to gen-
eralize, to learn from early experience.
John McCarthy (the founder of functional programming and the inventor of the
Lisp programming language) first mentioned the term "artificial intelligence" in
1956. However, Alan Turing formed the idea of such a system in 1935. The sci-
entist created a description of an abstract computer consisting of unlimited
memory and a scanner that moves back and forth through the memory. The
earliest successful artificial intelligence program was created by Christopher
Strachey in 1951, and already in 1952 it played checkers with a human and sur-
prised the public with its ability to predict movements (History of Artificial Intelli-
gence 2020). Nowadays, such programs are developing very quickly due to the
digitization of information and the growth of its turnover and volume.
3
AI algorithms are at the core of artificial intelligence, which exhibit some of the
behaviours associated with human intelligence. These include computer-en-
hanced learning, reasoning, perception, and imitating human cognitive activity
(History of Artificial Intelligence 2020). AI systems work by analysing large
amounts of labeled training data for correlations and patterns, which are used to
predict future states. For example, an AI language assistant that is fed text chat
examples can learn to produce a realistic conversation with people through Nat-
ural Language Processing (NLP) (Roldós 2020).
There are two types of artificial intelligence: strong AI and narrow AI. Strong AI
refers to programming that can replicate the cognitive abilities of the human
brain, such as cyber security. Narrow AI, on the other hand, is an AI system de-
signed and trained to perform a specific task, such as Apple's Siri.
AI is widely used in various fields from finance to healthcare, and it has become
integrated into everyday devices, such as vacuum cleaners. Examples of AI in-
clude chatbots, intelligent assistants, robo-advisors, email spam filters, and Net-
flix recommendations.
1. Probability-based methods
which also contains semantic relations. These continuous vectors create the de-
sired precision in the probability distribution of the next word. (Kapronczay
2022).
The most famous language models are GPT-3 (developers: OpenAI, parame-
ters: 175 billion), Bloom (developers: Hugging Face, BigScience; parameters:
176 billion), ESMFold (developers: Meta AI, parameters: 15 billion), Gato (de-
velopers: DeepMind, parameters: 79 million, 364 million and 1.18 billion),
LamDa (developers: Google, parameters: 137 billion). The number of parame-
ters in a language model is a measure of its ability to recognize complex pat-
terns and relationships in data and develop new emergent capabilities.
(Wodeski 2022).
2.3 OpenAI
During its seven years of existence, OpenAI has developed many artificial intel-
ligence tools that perform specific tasks. They are as follows:
6
3. The OpenAI Debate Game simulates a debate between two or more partici-
pants using artificial intelligence.
4. OpenAI Dactyl is a robotic hand designed to learn and adapt to new tasks us-
ing machine learning algorithms.
5. OpenAI Generative models (including DALL-E and ChatGPT) are artificial in-
telligence systems trained to generate new, original content based on a set of
examples or a specific model. (A Guide to OpenAI and its Products and Ser-
vices 2023).
GPT-3 is a deep learning-based language model that can generate text that
closely resembles human-written content. In addition to text, it can also produce
code, stories, poems, and other forms of creative content. As a result of these
capabilities, it has gained significant attention and popularity in the field of natu-
ral language processing. The full version of OpenAI GPT-3 is, with approxi-
mately 175 billion parameters to be trained, the largest model trained so far
compared to other language models. (Cooper 2021).
The GPT-3 model differs from other language models in that it has a huge num-
ber of parameters to train, 10 times more than any previous model. In general,
the more parameters a model has, the more data is needed to train the model.
According to the authors, the OpenAI GPT-3 model has been trained with
around 45 terabytes of text data from various sources such as Wikipedia and
books. (Cooper 2021).
GPT-3 is not a single model but a family of models. Each model in the family
has a different number of parameters to be trained. The table in Figure 1 shows
each model, architecture, and corresponding parameters.
Encoder: The encoder receives the input and constructs a representation (its
features) from it. This means that the model is optimized to understand the in-
put.
Decoder: The decoder uses the encoder representation (features) along with
other inputs to generate the target sequence. This means that the model is opti-
mized for output.
A key part of transformers is the attention process, which allows the model to
understand which words are most important to consider when judging what the
sequence produces. In each iteration of the encoder, each word is given numer-
ical weights, which are then analysed by the decoder to determine key aspects
of the input text on which the output should be based. (Bard 2021).
Instruct GPT, or simply Instruct, is a powerful tool that allows users to fine-tune
the generation features of the GPT model language. Developed by OpenAI, In-
struct GPT allows users to train a model for specific tasks and generate text
personalized to their specific needs. This tool is designed to facilitate develop-
ers and researchers fine-tuning GPT for a wide range of natural language pro-
cessing (NLP) tasks such as language translation, text summarization, and
9
question answering. Instruct GPT allows users to train the model with their own
data, fine-tune the model for specific use cases, and create text that is relevant
and accurate. The goal of Instruct GPT is to facilitate and improve the automa-
tion of repetitive and time-consuming tasks of companies and organizations.
(Dongre 2023).
The key difference between GPT and Instruct GPT is that GPT can be fine-
tuned for any task, while Instruct GPT needs to be specifically fine-tuned for a
specific set of tasks. While Instruct GPT is highly proficient at certain tasks, its
narrower focus makes it less adaptable than the original GPT.
Compared to GPT-3, the new Instruct GPT models adhere better to English in-
structions, are less likely to produce false information, and at least slightly less
likely to produce harmful results.
One issue with GPT-3 is that it was trained to predict the next word from a large
data set and not safely perform the task the user wanted. To solve the problem,
OpenAI used a method called reinforcement learning with human feedback
(RLHF). Reinforcement learning is a technique that involves an AI agent making
decisions based on the actions it performs in its environment and the feedback
it receives in the form of rewards or punishments. (Cuofano 2023).
2.6 ChatGPT
Instruct GPT and ChatGPT are both models developed by OpenAI. However,
the biggest difference between them is in their intended use. ChatGPT is a con-
versational AI model trained to generate human-like responses in dialogue. On
the other hand, Instruct GPT is a task-oriented AI model that is trained to per-
form specific tasks such as code generation, text SQL queries, and summariza-
tion by following instructions given to it.
Both models are built on top of transformer architecture but Instruct GPT is
trained on more versatile tasks and is fine-tuned to perform specific tasks, while
ChatGPT is trained on more general conversational data. Instruct GPT is a spe-
cialized version of ChatGPT designed for a task-oriented context. (Dongre
2023).
ChatGPT works by collecting human-written data from the Internet and using
calculated predictions to answer questions and queries entered by the user.
The responses it generates are based on text queries and information from
which the AI language assistant "learns" more about various topics and how to
discuss them. (Pocock 2023).
It is well trained on biased and unbiased data in the form of texts from books,
articles, and websites. ChatGPT can reproduce output and reliability, which is
critical for many sensitive applications and other valuable AI systems. However,
it is still prone to error and relies on training data provided in 2021. (Pocock
2023).
11
Chapter introduces the idea and goals of the case project, technologies, and
tools that are used to create the application. After that, details of development
process are provided through this chapter such as key components of the appli-
cation, which are developed with React Native (Task List and Task Details), im-
plementation of user authentication and authorization through Firebase as well
as storing task details in Firestore database.
During the search for the best application idea to implement for an IT project,
ChatGPT provided 10 different options. The idea of creating a Task Manage-
ment application was found to be the most appealing, as it has the potential to
help individuals who often struggles with managing multiple tasks.
The application will allow users to create new tasks and filter them based on
their completion status. This will help users understand which tasks have been
completed and which ones still need to be done.
The basic functionality of the Task Management Application has been success-
fully implemented with the help of ChatGPT. The application consists of five
screens, including Authentication Screens for user login and registration, a Task
List Screen that displays all the tasks in a list, a Task Form Screen for creating
new tasks, and a Task Details Screen that allows users to view additional
12
details about a task, such as its description. The Task Details Screen also fea-
tures a Delete button, which enables users to remove tasks from their task list.
The application was developed using React Native, TypeScript, Expo, Firebase
Authentication, and Firebase Firestore. Both web and mobile applications are
divided into frontend and backend. Frontend refers to the part visible to the user
and its functions, while backend refers to the basis of the application, which the
frontend is designed to utilize.
In a React Native application, the line between frontend and backend can be a
bit blurry since much of the application logic and state management is handled
on the client-side. However, Firebase Authentication and Firestore can be con-
sidered part of the backend since they are cloud-based services that provide
authentication and data storage functionality.
Frontend:
Backend:
ChatGPT was used as a helpful tool throughout the mobile application develop-
ment process. Various application ideas were received from ChatGPT initially,
and then the AI language assistant was asked to determine the most suitable
elements to include, taking into consideration that it was a study project (Figure
3). Valuable advice was provided by chat bot throughout the entire process.
14
This list can be utilized to create a product design map. It has been decided that
first three components would be implemented in study case, only limited num-
ber of features in the first iteration of the product.
Chat bot also helped with the application folder structure (Figure 4) and with a
choice of colour scheme (Figure 5).
15
The colour schemes are created primarily from neutral colours, these schemes
are helpful and seems suitable for the Task Management application.
When the decision about the components to be used in the application was
made, the ChatGPT was asked for assistance in creating and styling individual
components (Figure 6).
16
ChatGPT helped to create new Firebase project for the React Native application
with the comprehensive and detailed answer. Firebase Authentication offers a
set of backend services, SDKs, and pre-built UI libraries to authenticate users to
the application, and the email/password sign-in method was chosen for this pro-
ject. Firebase Authentication has intuitive and user-friendly interface (Figure 8).
18
After Firebase project with the Authentication was created, ChatGPT was re-
quested to provide guidance on implementing Sign In and Sign Up screens in
React Native using Type Script with the Firebase Authentication. The main step
to initialize a Firebase project in a React Native mobile application is to create a
configuration object that contains the following fields: apiKey, authDomain, pro-
jectId, storageBucket, messagingSenderId, and appId. This information can be
easily obtained from Firebase Console.
The chatbot generated code for Sign In and Sign Up screens can be easily inte-
grated into the React Native project by copying and pasting the code (Figure 9).
19
The solution generated by ChatGPT for Sign In and Sign Up screens implemen-
tation in React Native has some disadvantages. One of them is that it does not
include import statements for the useState() React hook, which need to be
added manually in order for the code to work properly. Second one is the auth()
method, imported from react-native-firebase, is not compatible with Expo, which
I used for a smoother and faster development process. As a result, I had to use
the "firebase" library instead of "react-native-firebase". To avoid such issues in
the future, it is important to provide ChatGPT with more detailed information
about the project, such as how to implement Sign In and Sign Up screens in
React Native with TypeScript and Expo.
through Google. The decision was to refactor the code (Figure 10), when use
Firebase Modular API (v9), which is the newest version available.
Figure 10. Firebase initialization in React Native project (Firebase Modular API
(v9)).
After requesting assistance from chatbot to implement Sign In and Sign Out
screens, it provided recommendations for using Navigation in React Native to
improve the user experience of the application. This suggestion was very use-
ful.
The only issue with the advice provided by the chatbot on how to use Naviga-
tion in React Native was that it didn't include all the necessary code parts for the
implementation. As a result, when the code was copied and pasted into the ap-
plication project, an error occurred (“Cannot find name RootStackParamList”). It
was necessary to seek further information from the AI language model on how
to resolve this error (Figure 11).
21
The Chatbot also assisted with styling the Sign In and Sign Up screens. It of-
fered useful advice, such as using a simple colour scheme, ensuring that form
fields are easy to read, using contrasting colours for buttons, making sure but-
tons are large enough, and implementing responsive design.
Task creation is implemented through the Task Form screen (Figure 12). The
Task Form screen is a key component of the Task Management application that
allows users to add new tasks to their task list. Task Form consists of two Text
Input components for entering task item and task description, as well as an Add
Task button for submitting the task. When the user submits a new task using
the Add Task button, the task information is sent to Firestore and stored as a
22
new document in a 'tasks' collection. Each task document contains fields for the
task item and description, as well as metadata such as the creation date. This
data can then be retrieved and displayed in the Task List screen, allowing users
to see all their tasks.
During the development of the Task Form screen, assistance was requested
from ChatGPT to help with writing the code to add items to a Firestore collec-
tion.
Code example to add task to Firestore with React Native and TypeScript (Fig-
ure 13). In this example we are using db (const db = getFirestore(app)) with get-
Firestore() function from “firebase/firestore” library. Then, we're calling the add-
Doc() method on the “task”collection to add a new document with the task
23
The Task List (Figure 15) screen is a one of the most important components of
the Task Management application that displays all the user's tasks in an orga-
nized and easily accessible manner. This screen includes a list of all the user's
tasks and simple filter that allows the user to easily view their completed and
uncompleted tasks. It also allows users to navigate to the Task Details screen
by clicking on a specific task. Completed tasks are displayed with a blue back-
ground while uncompleted tasks are displayed with a white background on the
screen. This helps users easily identify the status of their tasks. By clicking the
plus button in the right bottom corner on the Task List screen, users can navi-
gate to the Task Form screen to create a new task. Task List screen provides
an efficient and user-friendly way for users to manage their tasks.
The task items displayed in the Task List screen are fetched from Firestore,
providing real-time updates to the user's task list.
There is a React Hook within filter function (Figure 16). This Hook is triggered
whenever the status of the filter is changed and is responsible for returning a fil-
tered list of tasks based on the selected filter status. The “useEffect” Hook is a
built-in React Hook that enables developers to perform side effects after a com-
ponent has been rendered. In this case, the Hook is used to apply the appropri-
ate filter to the list of tasks based on the value of the “filterStatus” variable.
The Task Details screen (Figure 17) provides users with detailed information
about a selected task, such as the task name and description. Users can also
mark the task as completed and delete the task from the list. The screen in-
cludes button for deleting the task.
26
Figure 17. Task Details screen with examples of completed and uncompleted
task.
The task deletion feature has been implemented with Firestore, allowing users
to delete tasks from their task list with ease.
There is a Switch component in Task Detail screen, which is used to toggle the
completion status of a task (Figure 18). The Switch component is a built-in Re-
act Native component that provides a visual toggle control. The “trackColor”
prop is used to define the colours of the switch when it is in the 'off' and 'on' po-
sitions. The “thumbColor” prop is used to define the colour of the switch toggle.
In this case, the “thumbColor” changes based on whether the task is completed
or not.
27
4 Results
ChatGPT can help mobile app developers improve their workflows. With an AI
language model, you can automate tasks, optimize coding practices, and iden-
tify potential areas for improvement. AI language models can also provide lan-
guage-specific recommendations and fixes to ensure code is accurate and func-
tional.
way, which can lead to a more engaging and enjoyable user experience. With
ChatGPT, developers can create chatbots, voice assistants, or other NLP fea-
tures for their mobile applications that can understand user requests in natural
language and respond in a useful way. (Top benefits of ChatGPT in Mobile ap-
plication development, 2023).
Another important benefit is the ability to automate repetitive tasks. This can
help developers save time and focus on more complex and creative tasks such
as developing new features and improving the user experience. For example, AI
language models can automatically generate snippets of code based on user in-
put, reducing the time and effort required to write new code from scratch.
The chatbot can identify potential areas for optimization in the code. By analys-
ing large amounts of code, AI language models can help identify inefficiencies
or areas where performance can be improved. This can help developers opti-
mize their code and ensure it runs as efficiently as possible.
Despite the many improvements that Chat-GPT has made, it still has certain
limitations. One major limitation is that it cannot yet adapt to changes in conver-
sation or context. Although it understands very well what the user is saying and
generates an appropriate response, it does not always help to understand the
29
changing context of the conversation. This may limit the success of the machine
conversation and may mean that the conversation may get stuck or cannot pro-
ceed any further. (Bansal 2023).
The chatbot can only provide answers from some time ago. ChatGPT data ends
in 2021. This can be a problem for those who don't know and can result in incor-
rect information being added when writing an essay or posting on a blog. The
fact is that AI can be useful when the user continues to use it with the utmost
caution. (The Limitations of ChatGPT 2023).
Limited domain expertise. Domain expertise refers to the knowledge and experi-
ence in a particular field or industry. ChatGPT is a general-purpose language
model and may not have the same level of expertise as a human expert in a
specific domain. Developers can fine-tune ChatGPT on domain-specific data to
improve its domain expertise, but it requires a significant amount of data and
expertise.
The interesting thing about the ChatGPT is that you can have an ongoing con-
versation with it, and it will remember your previous interactions.
If you want ChatGPT to assist you with adding a new feature to your applica-
tion, it is important to provide specific details such as the name of the feature,
31
the functionality it should have, and any relevant constraints or limitations. Addi-
tionally, you could provide examples of similar features in other applications to
give ChatGPT a better understanding of your requirements. This will help en-
sure that the suggestions and advice provided by ChatGPT are relevant and
useful to your specific needs.
Another way to use ChatGPT as a developer helper when building a mobile ap-
plication is to integrate it into your Integrated Development Environment (IDE).
Many popular IDEs, such as Visual Studio Code, offer extensions that allow you
to use ChatGPT directly within your development environment.
Here is an example, how Code GPT extension can be used within Visual Studio
Code (Figure 18). It is possible to generate code using ChatGPT, simply add a
comment (here is “create typescript function to get completed tasks”) for the
task you wish to accomplish and press the “Ctrl + Shift + I” keys together.
This will generate the code on the right side (Figure 21).
32
Apart from that, it is possible to select a code, right-click on it, and ask Code
GPT to explain the code, refactor it, find problems, debug, and more (Figure
22).
Figure 20. How to utilize Code GPT within Visual Studio Code.
5 Conclusion
The purpose of the engineering work was to develop a mobile application for
the task management using React Native technology, Firebase Authentication
and Firestore with the ChatGPT assistance and at the same time to study the
33
In the research phase, various materials, and articles about ChatGPT were ex-
plored to gain a comprehensive understanding of language models and artificial
intelligence. The history of ChatGPT and its creators were also studied, provid-
ing valuable insights into its capabilities and potential applications.
Artificial intelligence is developing more and more every day, and ChatGPT is a
clear proof of this. This versatile chatbot can already compete with humans in
intellectual and communicative tasks. The use of ChatGPT is expanding, and
this trend will continue.
References
A Guide to OpenAI and its Products and Services. 2023. Online. The Windows
Club. <https://www.thewindowsclub.com/a-guide-to-openai-and-its-products-
and-services>. 9.1.2023. Accessed 7.2.2023.
Bard, Jonah. 2021. How GPT-3 Actually Works, From the Ground Up. Online.
Medium. <https://medium.com/nerd-for-tech/how-gpt-3-actually-works-from-the-
ground-up-5714ae7f3355>. 9.3.2021. Accessed 25.2.2023.
Borozenets, Michael. 2022. React Native Init vs Expo 2022: What Are the Dif-
ferences? Online. Fulkrum. < https://fulcrum.rocks/blog/react-native-init-vs-
expo#what-is-expo>. 22.4.2022. Accessed 14.2.2023.
Cooper, Kindra. 2021. OpenAI GPT-3: Everything You Need to Know. Online.
Springboard. <https://www.springboard.com/blog/data-science/machine-learn-
ing-gpt-3-open-ai/>. 1.11.2021. Accessed 8.2.2023.
Cuofano, Gennaro. 2023. Instruct GPT And Why It Matters For The Success
Of ChatGPT. Online. FourWeekMBA. <https://fourweekmba.com/in-
structgpt/>. 13.2.2023. Accessed 25.2.2023.
Dongre, Anay. 2023. Discover the Revolutionary Instruct GPT. Online. OpenGe-
nius IQ. <https://iq.opengenus.org/instruct-gpt/>. 2023. Accessed
25.2.2023.
Lowe, Ryan & Wainwright, Caroll. 2022. Instruct GPT Model Card. Online.
GitHub. <https://github.com/openai/following-instructions-human-feed-
back/blob/main/model-card.md>. 1.2022. Accessed 25.2.2023.
Ot, Annina. 2022. What Is OpenAI and Does It Really Make Coding Easier?
Online. MUO. <https://www.makeuseof.com/openai-coding/>. 19.1.2022. Ac-
cessed 7.2.2023.
Reyes, Kate. 2023. What is Deep Learning and How Does It Works. Online.
SimpliLearn. <https://www.simplilearn.com/tutorials/deep-learning-tutorial/what-
is-deep-learning/>. 17.2.2023. Accessed 7.5.2023.
Roldós, Inés. 2020. NLP, Machine Learning & AI, Explained. Online. Mon-
keyLearn. <https://monkeylearn.com/blog/nlp-ai/>. 9.6.2020. Accessed
25.2.2023.
Wodeski, Ben. 2022. 7 language models you need to know. Online. AI Busi-
ness. <https://aibusiness.com/nlp/7-language-models-you-need-to-know>.
27.7.2022. Accessed 25.2.2023.
What is GPT-3, How Does It Work, and What Does It Actually Do? 2021.
Online. Medium. <https://medium.com/sciforce/what-is-gpt-3-how-does-it-work-
and-what-does-it-actually-do-9f721d69e5c1>. 17.9.2021 Accessed 7.2.2023.