ChatGPT AI - Ask Me Anything! (Difficulty: 1)
-
Introduction
This is a very simple tutorial that shows how to use the ChatGPT block to create a virtual character that can answer user questions.
Step 1 - A New Project
Sign in to the CreatiCode playground, and create a new project. You can name the project as “Ask me anything”.
Step 2 - Add Sprite and Backdrop (Optional)
You can pick any sprite and backdrop for this project. For example, a professor sprite over a library backdrop. Drag the sprite to the left to leave more space for the speech bubble:
Step 3 - Ask and Wait
When the green flag is clicked, the sprite should ask the user to input a question. We can use the “ask and wait” block like this:
It should look like this when you click the green flag button:
Step 4 - Get ChatGPT’s answer to this question
After the user input a question and press the ENTER key, the user’s input will be stored in the “answer” block. Note that it is called “answer”, but in this case, its content is actually the question from the user.
We will then send this question to ChatGPT and wait for its response:
Explanation of the parameters:- Request: the “answer” block is sent to ChatGPT as the request.
- Result: the response from ChatGPT will be stored in the “result” variable.
- Mode: the “waiting” mode means we will not run any block below this block until the full response from ChatGPT has been received and stored in the result variable.
- Length: We are setting a maximum length of 500, which means if ChatGPT’s response is too long, it will be cut off. Note that this is 500 tokens, so approximately 375 English words, since tokens can be a part of a word.
- Temperature: We are using a high temperature of 1, which makes ChatGPT more creative.
- Session: We are starting a new chat session, so there is no conversation history.
Step 5 - Say the Response
After the response from ChatGPT is stored in the result variable, we simply need to make the sprite say it with a speech bubble like this:
This is the final result:
Additional Challenges
Here are some additional challenges for you to try:
-
Continue the Conversation: Currently, ChatGPT does not “remember” previous questions and answers. You can change it by adding a new stack of code: whenever the sprite is clicked, ask the user to input a question, but when you send it to ChatGPT, use the “continue” session type.
-
Shorter Answers: Try to make the sprite give very short and concise answers each time. For a hint, changing the token limit won’t help, and you need to modify the request that is sent to ChatGPT.
-
info-creaticode