project 1 applying chatgpt to programming

38 0 0
Tài liệu đã được kiểm tra trùng lặp
project 1 applying chatgpt to programming

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Trang 1

VIETNAM NATIONAL UNIVERSITY

UNIVERSITY OF INFORMATION TECHNOLOGYFACULTY OF SOFTWARE ENGINEERING

PROJECT 1

APPLYING CHATGPT TO PROGRAMMING

INSTRUCTOR:NGUYEN CONG HOAN

NGUYEN DINH HOANG PHUC – 19522036

HO CHI MINH CITY, DECEMBER 2023

Trang 2

Acknowledgements

To complete this project, we would like to express our deep gratitude to Mr.Nguyen Cong Hoan, who has dedicatedly guided us, provided advice, andoffered practical directions for our work The insights and lessons we'vegained throughout the project will be valuable not only in the present butalso in the future The esteemed teachers at the University of InformationTechnology have imparted valuable lessons, not only in specializedknowledge but also in life skills and future professional endeavors Duringthe project implementation, our team inevitably encountered someshortcomings We sincerely seek your feedback and guidance to enhancethe project further Your insights will serve as a solid foundation for ourteam to undertake future projects We extend our heartfelt appreciation toyou

Trang 3

Table of Contents

1 - Overview 5

1.1What is ChatGPT? 5

1.2 Why is it? 6

1.3 Who built it? 6

1.4 Why is ChatGPT more popular than previous models? 8

2 - Understanding ChatGPT - A Look Behind the Scenes 10

3.3 Using ChatGPT from the Web 16

3.4 Bring ChatGPT into IDE 22

3.4.1 Github Copilot 22

4 - Using its API 24

4.2 Obtaining an API key 25

4.3 API Tokens and Pricing 26

4.3 Using OpenAI Python Library 28

4.4 Building a simple ChatGPT Clone 29

4.5 Building a YouTube Video Transcript Summarizer 32

5 - References 37

Trang 4

Table of Features

Figure 1 ChatGPT 4

Figure 2 OpenAI timeline 7

Figure 3 The field of Artificial Intelligence in layers 10

Figure 4 OpenAI Welcome Window 16

Figure 5 OpenAI Registration Window 17

Figure 6 ChatGPT Main Window 18

Figure 7 ChatGPT’s Custom Instructions 19

Figure 8 ChatGPT’s Custom Instructions Interface 20

Figure 9 Inline Suggestion 22

Figure 10 Github Copilot Chat Interface 23

Figure 11 Generate Commit Message Feature 23

Figure 12 Creating an API Key 24

Figure 13 The Tokenizer Tool 26

Figure 14 API Usage Interface 27

Figure 15 YouTube Video Transcript Summarizer Interface 34

Trang 6

1.2 Why is it?

What sets ChatGPT apart from other large language models is its capacityto produce responses that are more natural and less robotic, unlikeanything seen before This, together with its user-friendly interface, hascontributed to quick adoption and hype around the product ChatGPT hitan impressive milestone of reaching 1 million users in just five days afterits launch in November 2022 It has been making waves in thecommunity ever since, gaining attention from users and experts alike Inmany industries, ChatGPT is helping augment roles and makingemployees more productive Marketers can generate content faster,software engineers can start with boilerplate functions, and managerscan receive automated summaries of reports ChatGPT has received a lotof positive feedback for its overall performance compared to previousLLMs, however others remain skeptical There is still a lot of confusionabout the impact ChatGPT is expected to have on the AI industry,whether it will make some jobs redundant, and how it is going to changethe way we work

1.3 Who built it?

ChatGPT was built by the artificial intelligence research laboratoryOpenAI Founded in 2015, the lab started with the goal of building“artificial general intelligence” or AGI, software that possesses a level ofintelligence comparable to that of human beings OpenAI has madesignificant contributions to the field of AI, a few examples include:

Trang 7

 In 2020 OpenAI launched GPT-3 (GenerativePre-trainedTransformer), a large language model that sets new benchmarksfor natural language processing.

 In 2021 OpenAI released Codex, an AI system that translateslanguage to code and became the backbone of the popular AI pairprogrammer tool, GitHub Copilot which offers autocomplete-stylesuggestions as you code.

 In 2022, OpenAI launched Dalle-2, a deep-learning model thatgenerates high-resolution realistic images based on textinstructions This led to asignificant mass interest in the field ofGenerativeAI.

 In 2023 OpenAI releases GPT-4 with a paid subscription allowingusers access to the Chat GPT-4 tool The biggest difference betweenGPT-3 and GPT-4 is shown in the number of parameters it has beentrained with GPT-3 has been trained with 175 billion parameters,and GPT-4 is likely to be trained with 100 trillion parameters GPT-4 has more data than GPT-3, which is thought to significantlyimprove its performance (medium ChatGPT timeline) ChatGPT isone of the latest models developed by OpenAI, built as a variant ofthe GPT 3.5 model that is fine-tuned to better answer questionsand interact conversationally

Trang 8

Figure 2 OpenAI timeline

1.4 Why is ChatGPT more popular than previous models?

ChatGPT is built on top of the GPT 3.5 model fine tuned to interact in aconversational manner The dialogue format makes it possible forChatGPT to answer follow-up questions, admit its mistakes, challengeincorrect premises, and reject inappropriate requests Here area fewreasons why ChatGPT has become more popular than previous models:

• Conversational style

The dataset that ChatGPT was trained on includes a diverse rangeof conversational text, and it has been fine-tuned on severalspecific tasks such as question answering and dialogue generation.This allows it to perform certain tasks more accurately thanprevious models, such as dialogue generation, question answering,and language translation The wide range of language patterns and

Trang 9

styles in the training data also makes it better equipped forgenerating diverse and nuanced responses.

• Interface

Previous models didn’t have an interface, so they were mainly usedby developers ChatGPT’s free, user-friendly interface makes ithighly versatile and adaptable to different use cases and caters to anon-technical audience such as content creators, marketingexecutives, etc.

• Human-like responses

Compared to other large language models such asGPT-3, ChatGPTis much better at generating human-like responses This was madepossible by the use of reinforcement learning from humanfeedback (RLHF) This technical approach enabled the OpenAI teamto rank the different responses generated by the initial model Themodel was then refined to learn from the human rankings andchoose the best human-like response.

• Safety guardrails

To achieve mass adoption, it is critical to build responsible AIsystems OpenAI has developed several guardrails to build a moresafe and useful language model including substantial reductions inharmful and untruthful outputs by incorporating human feedbackin the model development process Even thoughChatGPT hasbecome more robust over time thanks to the feedback loop, it is, infact, very easy to find examples where it has provided incorrect or

Trang 10

misleading results in the past, demonstrating that the guardrailsare superficial and can be circumvented.

• Contextual awareness

OpenAI has designed ChatGPT to be capable of processing verylong sequences of text, allowing it to effectively capture long-termdependencies in the input data This helps ChatGPT maintaincontext and track the flow of a conversation, allowing it to provideappropriate responses even in complex or multi-turnconversations.

Trang 11

2 - Understanding ChatGPT - A Look Behind the Scenes

ChatGPT is an amazing web app that allows users to ask various questionsand receive a wide range of responses This browser-based applicationoffers exceptional productivity enhancements Moreover, it has thepotential to replace certain job functions, particularly benefiting individualsknowledgeable in its optimal usage.

In order to unleash the full potential of ChatGPT and grasp its capabilitiesand features, it is vital to gain insight into its development process andinner workings.

2.1 Its name

• “Chat” refers to its primary function, which is to engage users inconversation, assist with inquiries, and generate human-like textbased on input.

• “Generative” indicates that it is capable of generating text orresponses from a given input.

• “Pretrained” means that it has been trained on a large dataset of textbefore being fine-tuned for specific tasks This pre-training allows itto have a broad understanding of language and context.

• “Transformer” is the type of neural network architecture used in itsdesign Transformers are known for their ability to handle long-rangedependencies in text and are particularly effective for naturallanguage processing tasks.

Trang 12

2.2 Large Language Model

SO, VERY BASICALLY, LLMS ARE GIANT COMPUTERS THAT TRY TO FINDOUT THE NEXT WORD AFTER EVERY WORD.

Figure 3 The field of Artificial Intelligence in layers.

As LLMs, GPT-4 and ChatGPT are the latest type of model obtained in thefield of NLP, which is itself a subfield of machine learning (ML) and AI AIis a very broad term, but generally it is the development of computersystems that can perform tasks that typically require human intelligence.With this definition, many algorithms fall under the AI umbrella ML is asubfield of AI In ML, we do not try to directly implement the decisionrules used by the AI system Instead, we try to develop algorithms thatallow the system to learn by itself from examples Since the 1950s, whenML research began, many ML algorithms have been proposed in scientificliterature Among them, deep learning algorithms have come to the fore.

Trang 13

Deep learning is the field within ML that focuses on algorithms inspiredby the structure of the brain These algorithms are called artificial neuralnetworks They can handle very large amounts of data and perform verywell on tasks such as image and speech recognition and NLP.GPT-4 andChatGPT are based on a particular type of deep learning algorithm calledtransformers Transformers are like reading machines They payattention to different parts of a sentence or block of text to understand itscontext and produce a coherent response They can also understand theorder of words in a sentence and their context This makes them highlyeffective at tasks such as language translation, question answering, andtext generation

Trang 14

3 - Using ChatGPT

3.1 Some practical approaches

• Code Conversion: ChatGPT’s proficiency in understanding complexprogramming structures and its ability to generate precise codetransformations make it an ideal companion for developers seeking tostreamline their workflows.

Language to language (JavaScript to Python) File format to file format(Markdown to JSON) Framework to framework (React to Vue) CSS toSCSS, SASS, Tailwind…

Document Code: In practice, writing documentation is hard and cantake a lot of time and effort, so it isn’t a favorite task for manydevelopers, and it is often pushed to the side This is a seriousproblem because written documentation is the main way developersexplain how a software system should function and be used Poordocumentation significantly hampers software quality by obscuringthe understanding of the codebase But now, with new tools likeChatGPT entering the scene, there’s hope that poor documentationwon’t be a headache anymore ChatGPT can serve as a codedocumentation tool and assess its effectiveness in making codedocumentation a smoother process.

• Writing test cases

• Generating Dummy Data• Explain code

Trang 15

• Generate code• …

3.2 Prompt engineering

Good Prompt = Good Result

Prompt engineering is essential because it directly influences the qualityof results produced by language models Writing good prompts leads tobetter outcomes in terms of specificity, relevance, and readability Byinvesting time and effort into prompt engineering, programmers cantailor the generated content to be more specific and engaging.

The Role of Context: Context plays a crucial role in writing prompts.Without sufficient context, the information provided to ChatGPT may betoo limited, resulting in uninspiring outputs On the contrary, byproviding additional context, programmers can guide the language modelto generate more detailed and valuable content The inclusion of contextallows ChatGPT to better understand the desired goal and create contentthat aligns with specific requirements Therefore, context becomes a vitalcomponent of prompt engineering This context can be divided into twotypes: a role assigned to ChatGPT, and extra constraints or informationprovided Including a role specifies a more defined behavior for ChatGPTbeyond its default AI assistant capabilities.

• Adding a Role: Adding a role to the prompt is optional but cangreatly benefit certain prompts For instance, if the objective is tocreate a captivating tweet about hiking for posting on Twitter, aspecific role can be assigned to ChatGPT This role determines how

Trang 16

ChatGPT should behave and provides the necessary context forgenerating the desired output.

• Extra Constraints and Information: In addition to assigning a role,extra constraints or information can be included in the prompt.While this step is also optional, it is highly recommended as itimproves the quality of most prompts and subsequently enhancesthe responses generated by ChatGPT By incorporating suchconstraints, the prompt can guide ChatGPT to produce moreaccurate and desirable outcomes.

When adding context, use short-focused sentences with relevant data foroptimal results Ensure all important keywords are included withoutunnecessary information to avoid distractions Another important aspectof context is the output format By default, ChatGPT generates plain text,which suits most use cases However, ChatGPT can be employed forvarious scenarios For example, it can be used to generate dummy datafor project purposes, such as application development or data sciencepractice In such scenarios, specifying the desired output format, such asJSON or CSV, can be helpful Additionally, defining the target audience,tone, style, and length of the generated response can enhance theoutput’s effectiveness.

Utilizing Followup Messages: A key advantage of using ChatGPT is theincorporation of followup messages Since ChatGPT considers the entirechat history, not just the latest message, it enables a more comprehensiveunderstanding of the conversation context and results in improved

Trang 17

responses By leveraging followup messages, better starting points andrefined outputs can be achieved.

Leveraging Contextual Understanding: Since ChatGPT takes into accountthe entire chat history, including the follow-up messages, it is notnecessary to provide extensive information in each followup message Asimple message stating the desired goal or change is sufficient ChatGPTwill automatically connect the new message with the existing history toprovide contextually appropriate responses This powerful feature allowsfor efficient utilization of ChatGPT.

Importance of Refinement: It is not essential to have a perfect initialprompt when using ChatGPT The refinement of responses and achievedresults can be an iterative process over time The user can gradually fine-tune and improve the outcomes by sending follow-up messages andadjusting as needed Being aware of this key ChatGPT feature willsignificantly enhance the experience in using the platform effectively.

3.3 Using ChatGPT from the Web

Using ChatGPT from the Web Interacting with ChatGPT via the OpenAIwebsite is incredibly straightforward OpenAI provides a web-basedinterface that can be found at ChatGPT, enabling users to engage with themodel without any prior coding knowledge or setup required Once thewebsite is visited, questions or prompts can be entered, and the modelwill produce its best possible answer or generated text Notably, ChatGPTWeb also provides users with various settings and options that allowthem to track the conversation’s context and save the history of all

Trang 18

interactions with the AI This feature-rich approach to web-based AIinteractions allows users to effortlessly experiment with the model’scapabilities and gain insight into its vast potential applications To getstarted with the web-based interface, an account with OpenAI isrequired Once an account is created, the web interface can be accessedand the model’s capabilities can be explored, including various settingsand options to enhance the AI interactions.

Creating an OpenAI Account

Before using ChatGPT or the ChatGPT API, an account on the OpenAI website must be created To do that, visit https://chat.openai.com.

Figure 4 OpenAI Welcome Window

Simply clicking the Sign up button and following the prompts will accessthe registration window From there, the option to enter an emailaddress and click Continue, or to register using a Google or Microsoft

Trang 19

account, is available Once this step is complete, select a password andvalidate email, just like with any other website registration process.

Figure 5 OpenAI Registration Window

After completing the registration process, ChatGPT’s full range offeatures can be explored Simply clicking the Log in button and enteringthe credentials into the Log In window With this straightforwardapproach to access, the full capabilities of ChatGPT can be seamlesslyexplored and its power for natural language processing tasks can be seenfirsthand.

Now the features and functionality of the ChatGPT web interface can beexplored in greater detail The interface will be navigated and its variousoptions will be used to get the best possible results from the AI model.

Ngày đăng: 15/05/2024, 09:30

Tài liệu cùng người dùng

Tài liệu liên quan