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 - Prompt Challenge Game (Difficulty: 3)

ChatGPT AI - Prompt Challenge Game (Difficulty: 3)

Scheduled Pinned Locked Moved Tutorials
1 Posts 1 Posters 2.5k 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 Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

    Introduction

     
    When we use ChatGPT to help us with various tasks, we often need to fine-tune our prompt to get the desired response from ChatGPT. In fact, a core skill of prompt engineering is to make ChatGPT say what we want it to say in the format we prefer.

    In this tutorial, we will build a simple game for “prompt challenge”: the player needs to say something to ChatGPT to make it respond with ‘this is easy’. Of course, this game would be too easy if the player can say anything, so we will add 2 constraints on what the player can say: the player can not use the words ‘this’, ‘is’ and ‘easy’ in his prompt.

    e3.gif

     
     

    Step 1 - Start with an Empty Project

     

    On the CreatiCode playground, log in to your account, then create a new project named “prompt challenge”. Remove the “Sprite1” with the dog, and we will write code in the “Empty1” sprite.

     
     

    Step 2 - Add a Chat Window

     

    This game will be played as a chat between the player and ChatGPT. So let’s add a chat window that occupies the entire stage:

    8830cc9d-2324-48d1-ac20-3455ea4c6b5d-image.png

     
    Note that the “input rows” is 2, which will show 2 rows of user input at the bottom.

     
     

    Step 3 - Say the Requirement

     

    Next, we will tell the player the desired output and the requirement for the input. We will add that to the chat history, and pretend it is coming from ChatGPT. The exact words are the following:

    Make me say 'this is easy', but do not use any of these 3 words
    

     
    We can use the “append to chat” block to add this:

    e3.gif

     
    Now if we click the green flag, this requirement will show up right away:

    e3.gif

     
     

    Step 4 - Display Player Input

     

    When the player inputs some words in the chat window and presses Enter, we will store it in a variable called “input”, and also add that input to the chat window.

    b509fdc6-2d1d-4bb6-860f-2ce8c556b6a4-image.png

     
    This is what you should get now:

    e3.gif

     
    Of course, since we haven’t sent it out to ChatGPT, we won’t get any response yet.

     
     

    Step 5 - Check Player Input

     

    Before we send the player input to ChatGPT, we should verify if that input is valid. Our rule is that this input should not contain these 3 words: “this”, “is” and “easy”. So if the input contains any of them, it is invalid. We can use 2 “or” blocks to combine 3 conditions, where each condition checks if the input contains one of the 3 words:

    4569f4b2-a5da-46c8-a3e7-93292fb86c79-image.png

     
     

    Step 6 - Reject Player Input

     

    If any of the 3 conditions are true, we only need to tell the player to try again, and we won’t need to do anything else:

    e3.gif

     
    You can test it by inputting some invalid input that contains one of these words. Note that you can try multiple times, since each time it will trigger the “when widget chat1 clicked” block again.

    e3.gif

     
     

    Step 7 - Send Player Input to ChatGPT

     

    When the player input doesn’t contain those 3 words, we will send it to ChatGPT to see if we can get the required output back:

    958b9110-e9bb-44e1-b947-eff90eb704aa-image.png

     
    We will store the response from ChatGPT in the “response” variable. Since the response will be fairly short, we will simply use the “waiting” mode to wait for the entire response to come back. We will make this a “new chat” session each time the player says something because we don’t need ChatGPT to remember what the player said before. It only needs to respond to what the player is currently saying.

     
     

    Step 8 - Display ChatGPT’s Response

     

    Once we get the response from ChatGPT, we can append it to the chat history as well:

    bf0e52ef-137e-4d31-8267-ffae7fdd4bfd-image.png

     
     

    Step 9 - Check ChatGPT’s Response

     

    Now it’s time to check whether ChatGPT is saying exactly ‘this is easy’:

    6b07f953-ec5c-4fa9-b8a2-37948d29223e-image.png

     
    Note that we can simply use the equal operator. It will report true even if the case of the 2 sides are different. Also, this if-else block should be added inside the ‘else’ branch of the previosu ‘if-else’ block, since we only need to test the response if the player input is valid.

     
     

    Step 10 - Tell the Player the Result

     

    Lastly, we can either congratulate the player for passing the test or ask the player to try again:

    9ead8ed1-c5c8-4b85-b314-8f7b26021f17-image.png

     
    Now the game is ready for playing. Please try to play it yourself and find a solution. There are many ways to solve this puzzle. For a hint, one solution is to make use of the ‘opposite’ word.

     
     

    Create Your Own Prompt Challenge Game

     

    If you would like to player more, search for “Prompt Challenge” on the explore page. They will help you practice how to control ChatGPT’s output.

    In addition, try to think of a new challenge yourself. You will need to specify the desired output from ChatGPT and any constraints on the player input. Note that both the output and the requirement need to be easy to verify. Ideally, you should consider and prevent all possible ways the player may “hack” your challenge.

    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