Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. Tutorials
  4. ChatGPT AI - Cloze Game (Difficulty 4)

ChatGPT AI - Cloze Game (Difficulty 4)

Scheduled Pinned Locked Moved Tutorials
1 Posts 1 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CreatiCodeI Online
    CreatiCodeI Online
    CreatiCode
    wrote on last edited by admin
    #1

    Introduction

     
    In a “cloze game” (also called a “cloze test”), you fill in the missing word in a sentence. It’s a great way to practice telling similar words apart.

    In this tutorial, you’ll make an app that uses ChatGPT to create cloze games from any words the user types in. You’ll learn how to write the right kind of prompt to ask ChatGPT for help, and how to make your app understand the response. You’ll also design a more advanced user interface, which makes this a good project for learning how to use the widget blocks.

    When you’re done, your project will look like this:

    s3.gif

     
     

    Step 1 - A New Project

     
    In the CreatiCode playground, create a new project named “Cloze Game”. Remove the “Sprite1” block, as we will only need the “Empty1” block.

     
     

    Step 2 - Send Prompt and Print Response

     
    In the next few steps, we’ll focus on writing a good prompt for ChatGPT. After that, we’ll build the part of the program that uses ChatGPT’s reply. This is how most AI apps are built: we start by making sure ChatGPT gives us the right kind of answer. If it doesn’t, there’s no point in building the rest of the app.

    Since the user won’t be talking directly to ChatGPT, we don’t need to send any system messages. We’ll just use a regular request block like this:

    f6cd154a-1df9-49a9-8e5a-dd6fdb57e9a7-image.png

     
    Remember: when the request is in “waiting” mode, we wait until the full response is saved in the “response” variable before we move to the next block, which will print it in the console. With these blocks in place, we are ready to design and test the prompt.

     
     

    Step 3 - Start with A Simple Prompt

     
    The cloze game is very common, so ChatGPT has already seen lots of examples. We can begin by just asking it to make a cloze game and there is no need to explain what it is. Later, we’ll improve the prompt depending on the results we get.

    For now, we can “hardcode” (type in ourselves) three words like “run, runs, ran.” We’ll let the user enter their own words later.

     

    d273d4d7-df43-44aa-a198-c9880f62bc00-image.png

     
    Try running your project a few times. Look at what ChatGPT gives back. What problems can you find? How can you improve the prompt to fix them?

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     
     

    Step 4 - Analyze ChatGPT’s Response

     
    Here are a few example outputs printed in the console panel. Note that the “Empty1” at the beginning just means the log is printed from that sprite, so you can ignore that.
     

    b9e07157-392a-4fe1-88df-2f024cae176f-image.png

     

    b5683c96-1207-411a-8eb0-a63fe37fe928-image.png

     

    1445df4c-90f3-46d7-a661-e8a293abc1c5-image.png

     

    3d14fd3b-8f0d-4ba2-9511-3d6615b83412-image.png

     

    66308bee-099d-481b-94f8-7c753eb17dbb-image.png

     
    Here is a summary of the key issues:

    1. The reply might be too long. That can exceed the word limit and cause the user to wait longer.
    2. Sometimes you don’t get exactly 3 questions. Or it comes as one big paragraph, which is harder to use for our app.
    3. Sometimes the answers are shown, sometimes not. We don’t want the user to see the answers, but our code still needs them.

     
    The first 2 issues are relatively easy to fix. Can you give it a try before moving on to the next step?

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     
     

    Step 5 - Fix Issues with Token Count and Question Count

     

    We can use the following request to fix some of the problems fairly easily:

     

    in 60 words, create a cloze game with 3 questions for these words: run, ran, runs
    

     
    Here are some example outputs from this updated prompt:

    ab33e94f-82c6-4558-a5cf-6f7d54532268-image.png

     
    5a03bdba-840e-45ba-a52e-ea57d3dc6fa7-image.png

     
    2af68e52-ddb1-4bf3-87a3-89602c481146-image.png

     
     

    Step 6 - Specify Response Format

     

    To make it easy for our program to process the response, we need to make the response strictly follow a predefined format. To do that, the best solution is to specify the format ourselves in the prompt.

    For example, this is an updated prompt:

     

    
    in 60 words, create a cloze game with 3 questions for these words: 
    run, ran, runs
    
    use this output format:
    
    QUESTIONS:
    
    1.
    2.
    3.
    
    ANSWERS:
    
    1.
    2.
    3.
    

     
    Now the output looks better (still not perfect):

     
    f16b3ae1-4938-4018-bab0-fad323b3d399-image.png

     
    7e25cb03-3d06-44b9-9eb5-d2df823c3edb-image.png

     
    Next, we need the answers to be ONLY the hidden words themselves, not entire sentences. That way, our program can easily parse the output. Can you try to make this change?

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     
     

    Step 7 - Answer Format

     

    We don’t want full sentences for the answers—just the missing word. There are two ways to do that:

    First, say clearly in the prompt: only show the hidden word for each answer.

    Second, show ChatGPT an example of how the format should look.

    Here’s an updated prompt that does both:

    
    in 60 words, create a cloze game with 3 questions for these words: 
    run, ran, runs
    
    use this output format (for each answer, only show the hidden word):
    
    QUESTIONS:
    1.
    2.
    3.
    
    ANSWERS:
    1. hidden word
    2. hidden word
    3. hidden word
    

     

    With this new request, the response from ChatGPT will be fairly consistently formatted like this:

    e4817c1a-d11d-469a-97d7-d88d48fc83a2-image.png

     
    Now that we have optimized the ChatGPT request, we can begin working on the user interface.

     
     
     
     

    Step 8 - Let the User Enter Words

     
    Next, we need to let the user type in three words they want to use in the cloze game.

    We’ll do this by adding textbox widgets for the words. We’ll also add labels next to the textboxes to mark them as “A”, “B”, and “C”. This will help later when the user chooses the missing word from a dropdown.

    Here’s what it might look like:

     
    d6c6760c-9c5a-4269-9524-fd437a54e5b4-image.png
     

    To keep things organized, create a new custom block and call it “word inputs”. Add the widget blocks yourself and use the Widget Position tool to adjust their sizes and positions.

    Important: Detach the ChatGPT block for now — we don’t need to call it while building the interface. It would make things slower.

    Here is an example program:

    e8cb68c3-4bb2-4aa1-b823-9048f2ecd71d-image.png

     

     
     

    Step 9 - Show the Questions

     

    Once the user has typed in three words and clicks a “Create” button, we’ll send the request to ChatGPT. When the questions come back, we’ll show them in a multi-line textbox that the user can read but not edit.

     
    7b0097c6-2642-4159-8e29-cf6cc50051bd-image.png
     

    We will define a new custom block “add questions” and add these 2 widgets:

    403ddde5-2b67-49de-8ac5-f8bbced7974e-image.png

     
     

    Step 10 - Create the “choices” List

     

    At the bottom of the screen, we’ll add dropdowns so users can pick the right word for each sentence. For that, we’ll create a list called “choices” and add the letters “A”, “B”, and “C” to it.

    Note: Sometimes the widgets might cover part of the stage, so you can’t see the list clearly. To fix this, click the green flag button without running any other blocks. That will clear the stage:

    choic.gif

     
     

    Step 11 - Add Answer Dropdowns

     

    Now it’s time to show the dropdowns where the player picks their answers, along with a “Submit” button:

    85d3280c-0911-417a-b44a-fb6e60d16026-image.png

     
    To keep your code neat, group the new blocks under another custom block called “add answers”:

     
    3ac2bed3-b251-489a-a516-2a0a1cac4de3-image.png

     

    By now, we have completed the game interface. For the last few steps, we will need to handle user actions with the help of ChatGPT.

     
     

    Step 12 - Compose the ChatGPT Request Using User Words

     

    Earlier, we hardcoded the words as “run, runs, ran.” Now we’ll switch to using the user’s input words in the request we send to ChatGPT.

    To make our code easy to read, we will create 3 variables and join them together: task, words and format. We will store the final request in another new variable called “request”.

    • task will be the part of the request before the 3 words. It describes what we need:
    in 60 words, create a cloze game with 3 questions for these words: 
    

     

    • words contains the 3 user words, separated by commas.

     
     

    • format tells ChatGPT exactly how to format the response:
    use this output format (for each answer, only show the hidden word):
    
    QUESTIONS:
    1.
    2.
    3.
    
    ANSWERS:
    1. hidden word
    2. hidden word
    3. hidden word
    

     
     
    Here are the blocks to compose the request when the user clicks the “Create” button:

    59d115ba-3aa6-4a7a-bf41-18bc9b397aed-image.png

     
     

    Step 13 - Send the Request and Show the Response

     

    Now that we’ve built the request, we can send it to ChatGPT and show the reply in the textbox for the user to read:
     
    db862df2-802e-4eb0-850f-e61aa478c101-image.png

     
    Try to test it out with some new words:

    s1.gif

     

     
     

    Step 14 - Remove the “QUESTIONS:” header

     

    Right now, the output always starts with “QUESTIONS:”, which makes the formatting look off.

    To fix that, we can use a replace block to delete that line:

     
    23d15780-f605-48ed-b49a-d08fa0520b6b-image.png

     
    As shown, you can detach these blocks from the ChatGPT request and run them alone, so we won’t need to rerun the ChatGPT request. Now we get a better-formatted question list:

    54909182-4372-4ca2-8130-9c4cbe123de1-image.png

     
     

    Step 15 - Extract Questions and Answers

     

    The ChatGPT response includes both the questions and the answers. But we only want to show the questions to the user.

    We can split the response into two parts using the word “ANSWERS:” as the divider.

    • The first part (before “ANSWERS:”) goes into the questions variable.
    • The second part (after “ANSWERS:”) goes into the answers variable.
       
      6ab8d834-42aa-4de4-b933-fa7d271aa12a-image.png

     
    Now the textbox only shows the questions:

    007f752d-be1a-4789-b9a3-33b1c93a7cbe-image.png

     
     

    Step 16 - Check the Player’s Answer to Question 1

     

    When the player clicks the Submit button, we’ll check if their answers are correct.

    Start by making a block called check answer 1.

    It will figure out which word the player picked for question 1 and save it in a variable called user answer:
     

    31f37f7f-1ca5-455b-ab80-6497e5eba0ce-image.png

     
    For example, suppose the 3 words are A) “word1”, B) “word2” and C) “word3”. If the user has chosen “B” for the first question, then the “user answer” variable will be set to “1. word2”.

    Make sure there’s a space after the dot! Otherwise we won’t be able to compare it with the answers from ChatGPT.

     
     

    Step 17 - Verify the User’s Answer

     

    Now let’s check if the user’s answer matches one of the correct answers from ChatGPT.

    If they’re right, we’ll turn the dropdown green. If not, it turns red:

     

    s2.gif

     
    Here is how to achieve this:

    59537168-784b-4879-b0f2-38ab255cf54f-image.png

     
     

    Step 18 - Check the Other 2 Answers

     

    Lastly, we just need to check answer 2 and answer 3 in a similar way.
     
    826052f0-53a9-4641-872f-fc66da01e264-image.png

     
     

    Final Result!

     

    When you’re done, your full cloze game app will be ready to play:

    s3.gif

     
     

    Additional Challenges

     

    This tutorial only covers the core logic of the project to keep it short. There are a lot of areas where you can improve upon it or adapt it. Here are some ideas for you to try:

    • You might find that ChatGPT tends to order the 3 questions the same way as the 3 input words, so the correct answers are always A/B/C. Can you modify the prompt so the 3 questions are randomly ordered? Alternatively, you can change the order of these 3 input words randomly in your prompt that’s sent to ChatGPT.

    • Instead of having the user input the 3 words, use a predefined list of words. For example, define a list of 30 words, and run through them 3 by 3. This would be useful for a teacher who wants to test students on some specific words.

    • Use the “streaming” mode for ChatGPT, so that the user can see the questions as they get generated. It will reduce the waiting time a lot.

    • Add colors to the widgets to make them look better.

    • Make sure the questions from ChatGPT are properly formatted. For example, you need to avoid getting questions like this:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/9f3e12a9-e7da-44cf-85c1-2106046ec30d.png" width="500" style="margin-left: 40px">

     
    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/932534fc-5d04-416b-8c21-db6c046de24b.png" width="500" style="margin-left: 40px">

    • Fix “run” vs “runs”: sometimes one of the words from the user input contains another word. For example, suppose the words are “run, ran and runs”, and an answer is “1. runs”. Then, when we check if the correct answers contain “1. run”, we would get a match, though that’s the wrong answer.
    1 Reply Last reply
    0
    • CreatiCodeI CreatiCode pinned this topic on

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode