GenAI HW3�以API快速搭建自己的應用
Using ChatGPT Model by Browser
In the HW2, we use ChatGPT model through the browser interface
Browser
2
ChatGPT model
User query
Response
Creating Your Own Application Using ChatGPT
For example, you want to create an App (應用程式) that adds appropriate emojis to any given input, and you want to power it by ChatGPT
3
ChatGPT model
Human evaluation is indispensable and inevitable for assessing the quality of texts generated by machine learning models or written by humans.
User input:
Paragraph with emoji:
Human evaluation 🧑🔬 is indispensable and inevitable 🚫 for assessing the quality of texts 📝 generated by machine learning models 🤖 or written by humans 📖.
Emoji Adder App
Creating Your Own Application Using ChatGPT
While you can manually copy the user input to the browser and copy the response from ChatGPT to the user end, this is too slow
Browser
4
Human evaluation is indispensable and inevitable for assessing the quality of texts generated by machine learning models or written by humans.
User input:
Paragraph with emoji:
Human evaluation 🧑🔬 is indispensable and inevitable 🚫 for assessing the quality of texts 📝 generated by machine learning models 🤖 or written by humans 📖.
Emoji Adder App
Creating Your Own Application Using ChatGPT API
The ChatGPT API (Application Programming Interface) enable programmatic (程式化的) interaction with the ChatGPT model
Response: ………..
5
ChatGPT model
Human evaluation is indispensable and inevitable for assessing the quality of texts generated by machine learning models or written by humans.
User input:
Paragraph with emoji:
Human evaluation 🧑🔬 is indispensable and inevitable 🚫 for assessing the quality of texts 📝 generated by machine learning models 🤖 or written by humans 📖.
Emoji Adder App
Creating Your Own Application Using ChatGPT API
You tell ChatGPT what you want it to do in a programmatic way
Response: ………..
6
ChatGPT model
Human evaluation is indispensable and inevitable for assessing the quality of texts generated by machine learning models or written by humans.
User input:
Paragraph with emoji:
Human evaluation 🧑🔬 is indispensable and inevitable 🚫 for assessing the quality of texts 📝 generated by machine learning models 🤖 or written by humans 📖.
Emoji Adder App
Creating Your Own Application Using ChatGPT API
ChatGPT return the response by following you what you ask it to do
Response: ………..
7
ChatGPT model
Human evaluation is indispensable and inevitable for assessing the quality of texts generated by machine learning models or written by humans.
User input:
Paragraph with emoji:
Human evaluation 🧑🔬 is indispensable and inevitable 🚫 for assessing the quality of texts 📝 generated by machine learning models 🤖 or written by humans 📖.
Emoji Adder App
What You Will Learn in This Homework
You will learn how to build some simple applications using ChatGPT with its API
8
2.
What You Will Learn in This Homework
You will learn how to build some simple applications using ChatGPT with its API
9
Overview in Today’s TA Lecture
10
Warning of Codings
11
No worries, the TAs have already written the codes.
12
Outline
13
Links
14
Colab and Gradio Tutorial
15
Introduction
What is Colab?
Colab, or "Colaboratory", allows you to write and execute Python in your
browser, with
16
Introduction
What is Gradio?
Gradio is a tool that allows you to demo any application with a friendly website so that anyone can use it, anywhere.
17
We will use the following google colab notebook for tutorial demonstration
Demo for Colab and Gradio Tutorial
18
19
Create a copy in your drive
20
File location
You can change the name here
If it looks like these:
Hit it again.
Click this to unfold the blocks
21
Upload your file
Download your file
If you accidently click this
You can find your files here
Cells
Create a new cell by clicking on + Code or + Text
22
These options allow you to moving your cell up/down or copy and deleting it
Run Cell
Run Cell by clicking on the
23
Code Unexecuted
Code Executing
Code Executed
Error Occurred
Problems you may encounter
Colab will automatically disconnect if idle timeout (90 min., sometimes varying) or when your screen goes black.
If you “Disconnect and delete runtime” or “Restart Session”, your files will be gone.
24
25
Run these three blocks from top to down
26
Click this link will lead you to a browser version gradio
You can also use gradio inside colab
27
Dialogue
Input box
Click Send to enter your input
Click Reset to reset the dialogue
29
30
When it’s spinning, the gradio is connected to the colab.
When it stops, the gradio will no longer work.
Available APIs
31
Available APIs
You only have to choose one API to use.
Google Gemini API
ChatGPT (OpenAI API)
32
Available APIs: Google Gemini
33
Google Gemini API
34
Demo for Gemini API key
35
Step 1: Accept Terms of Service
36
37
Step 2: Get API Key
38
Step 3: Create API Key
39
Final: Copy
40
Problems you may encounter
41
IF
THEN
Problems you may encounter
42
THEN
Issue #2
Do not use G-Suite accounts, use your own account
43
Available APIs: ChatGPT API
44
Step 0 - Go to OpenAI Website
45
Demo for ChatGPT API key
46
Step 1 - Login/Create Account
47
Step 2 - Create Account(Cont.)
48
Step 3 - Check Usage
49
Step 4-1 - Phone Verification
50
Step 4-2 Create API key
51
Step 4-3 Copy and take good care of your API key !!!
52
OpenAI API - Free Usage
53
Task Introduction
54
Workflow
1. Call API
Summarization
Role Playing
Customized Task
2. Evaluate Task
Use Davinci Platform to grade your task
Model: GPT-4
3. Submit to NTU COOL
Task
Objective:
Understand how to build your own Language Model Application by calling API and feeding prompts.
Task:
Colab link to this homework:
https://colab.research.google.com/drive/15jh4v_TBPsTyIBhi0Fz46gEkjvhzGaBR?usp=sharing
56
Task Introduction: �Task 1: Summarization
57
Task 1: Summarization
58
USER
Language
Model
Help me summarize ……
[Given article]
Summarized article
59
Prompt
Article
Summarization
Send
Browser
API Call
60
60
Prompt
Article
Prompt
Article
Send
Send
61
Summarization
Summarization
Step 0
Choose one of the API you want to use
We will use ChatGPT API in the following slides and later demonstrations.
62
Click one of these two buttons to unfold the codes
Step 1
2. Enter your ChatGPT API key here and run this cell
63
Fill in your ChatGPT API here
Remember to run these two cells whenever you reconnect to colab.
Step 2
Under this text cell Part1: Summarization
Fill in your prompt for summarization in "FILL IN YOUR PROMPT" and hit the run button.
Example: “Please summarize this article for me.”
64
Step 2
The prompt you just filled in will be used in the API call to instruct ChatGPT what it should do
65
Step 3
There will be a gradio interface like this pop up.
66
Here you can enter whatever article you want to summarize
Step 3
The article will also be a part of the input to ChatGPT
67
Step 4
68
You can use this slider to adjust the temperature here.
The higher the temperature, the more creative response you will get.
Hit “Send” to get the response.
Step 5
The response will display in gradio like this
69
Save your results
For each tasks, after you get a satisfied result. Make sure to hit the “Export” button.
If you hit the “Export” button again, the old file will be replaced.
70
Save your results
After that, you will see the file appeared in the file list.
Make sure to download it to your own computer before it disappear.
71
After you save your results …
Go to “Check and print your result” for the corresponding part
RUN IT
72
Copy
Paste
73
Demo for Task 1
74
Task Introduction: �Task 2: Role Playing
75
Task 2: Role Playing
76
USER
Language
Model
I want you to act as a pirate. Explain your job to me.
I'm a digital pirate, sailing the info-seas! 🏴☠️
Rules: Role Play
77
USER
Language
Model
Input: You are Shakespeare. Write me a really short poem.
"In moon's soft glow and star's tender light, Love whispers true in the hush of night."
Note: Observe the multi-turn conversation (history of conversation recorded)
78
Prompt
Send
Output
79
History
New Input
New Output
80
Input
Send
Input
Send
81
History
New Input
History
user: The input you typed
assistant: The output the bot generated
New Input
When using API, you have to record the history manually.
82
New Output
New Output
When using API, you have to record the history manually.
83
When using API, you have to record the history manually.
Whole Dialogue
Whole Dialogue
Note
Role: Fill in the role you want and it will be in the red block below
Input: Actual Input for conversation.
84
Demo for Task 2
85
Task Introduction: �Task 3: Customize Task
86
Task 3: Customize Task
Be Creative!
87
Task 3: Customize Task
88
USER
Language
Model
Prompt: “Give me the antonym of the following words”
Input: “Big”
Result: “Small”
89
Prompt
Input
Output
Send
90
Prompt
Input
Prompt
Input
Send
Send
91
Output
Output
Both single-turn and multi-turn is acceptable.
Note
Fill in the description of your task and it will be in the red block below
(e.g. Give antonym )
Actual Input for conversation.
92
Demo for Task 3
93
How to Delete Your API Keys
94
OpenAI API
95
Click here to remove the delete API keys
Gemini API
96
Click here to remove the delete API keys
Issues You Might Encounter
97
ModuleNotFoundError : No module named ‘xxx’
98
Solution: Execute corresponding code block (e.g. !pip3 install xxx)
NameError : name ‘List’ is not defined
99
Solution: Execute this code block
FileNotFoundError : [Errno 2] No such file or directory
100
Solution:
Please check if there exists the required json file
1.
Gradio UI not showing : block running but not working
101
Solution:
Check and stop other running code blocks
Wrong API key
102
Prompting Issue
Problem: Several prompts will encounter such error.
Solution: Change your prompts
103
Evaluation Assistants on DaVinci for Grading
104
Grading
Model Version: GPT-4-Turbo-8k
Assistant: GenAI Homework3 Assistant
Copy your result to the Grading Assistant in DaVinci Platform.
Link of Davinci Platform: https://dvcbot.net/
105
DaVinci Install Assistant
106
107
1. Press “+ Chat”
2. Choose “Assistant”
108
2. Click “GenAI Homework3 Assistant”
1. Search “GenAI Homework3 Assistant”
109
1. Install
DaVinci Grading
110
111
2. Click to see Assistant list
1. Create a new chat for each task
3. Choose
(GenAI Homework3 Assistant)
⚠️ Ensure to open a NEW chat every time you re-evaluate the result
4. Choose your Grader/Task
112
Fill in these textbox with results from Colab
113
Press this to download as .json file
Assistant gives feedback and a final score for your essay
Demo for Evaluation Assistants on DaVinci for Grading
114
Daily Usage Limit
There is a daily usage quota limitation on the DaVinci platform, based on your quota, you can run
115
You can also check the bottom left of Davinci Platform remaining usages
Note: This depends on the amount of words you input
BE CAREFUL
Avoid Harmful Prompts and Tasks
116
Evaluation Prompts for 旁聽生
For those who wants to judge their score by themselves, we provide the full prompts for evaluation list here:
To use the prompt, replace the contents inside {{ }}.
Eg. Replace “{{article}}” by your article in summarization task.
117
Submission
118
Submission (NTU COOL)
<student_ID>_part1_hw3.json
<student_ID>_part2_hw3.json
<student_ID>_part3_hw3.json
119
Submission (NTU COOL)
⚠️ We will compare the files you submit with our backend data records to ensure they match. Therefore, please do NOT manually edit your JSON file.
120
Important Dates
121
Important Dates
2024/03/21 23:59:59 (UTC+8)
2024/04/04 23:59:59 (UTC+8)
122
Regulations
123
Regulations
124
If You Have Any Questions