Introduction: The Role of Prompt Data in the Game

Welcome back! In the previous lesson, you learned about the LLM Prediction Game — how it works, how players interact with it, and how their guesses are scored. Now, we are ready to start building the data that powers the game.

In this lesson, you will learn how to generate the prompt data that the game uses to ask questions. This data is essential because it provides the daily questions and the structure that the game relies on. By the end of this lesson, you will know how to create a set of prompts, each with a question, some settings, and a few random elements to keep the game interesting.

Key JavaScript Concepts for This Lesson

Before we dive in, let’s quickly review a few JavaScript basics that will be useful in this lesson:

  • Arrays: A way to store multiple items in a single variable, using square brackets [].
  • Random Selection: The Math.random() function helps us pick random items from an array.
  • Saving Files: In Node.js, we use the fs module and JSON.stringify() to write data to a file.

If you need a refresher on any of these, feel free to look at the JavaScript documentation. Otherwise, let’s move forward!

Building a Prompt Entry: What Goes Into Each Question

Each prompt entry in our game is a small package of information. Let’s break down what each entry contains:

  • llm: The name of the language model we are using (for example, "gpt-4o").
  • systemPrompt: Instructions for the model (for example, "You are a helpful assistant. Your answers must only contain 10 words.").
  • userQuestion: The question that will be shown to the player.
  • breakpoints: An array of numbers that will be used later in the game logic.

Let’s look at a simple example of what one entry might look like in JavaScript:

This object holds all the information for one prompt. In the next steps, we’ll see how to generate many of these entries automatically.

Generating User Questions and Breakpoints

To make the game interesting, we want a variety of questions and some randomness in the breakpoints. Let’s build this step by step.

Step 1: Creating a List of Topics

First, we need a list of topics or nouns that our questions will be about. Here’s a small example:

Step 2: Making Questions from Topics

We can use these nouns to create questions by combining them with a template. For example:

Output:

This gives us an array of questions ready to use.

Step 3: Randomly Selecting Breakpoints

We want each prompt to have a set of breakpoints. Let’s create an array of possible breakpoint options and pick one at random for each entry.

Output (example):

Note: In JavaScript, there is no built-in way to set a random seed for reproducibility as in some other languages. Each time you run this code, you may get a different selection.

Step 4: Assembling the Full Entry

Now, let’s put it all together for one entry:

Output (example):

Saving the Prompt Data to a JSON File

Once we have many entries, we want to save them so the game can use them later. In Node.js, we use the fs module and JSON.stringify() for this.

Let’s say we want to create 3 entries and save them:

This code creates an array of entries and writes them to a file called data.json. The null, 2 part in JSON.stringify makes the file easy to read.

Note: This code works in a Node.js environment, not in the browser. Make sure you have permission to write files in your working directory.

Summary and What’s Next

In this lesson, you learned how to:

  • Build the structure for a prompt entry.
  • Generate a list of user questions from a set of topics.
  • Randomly select breakpoints for each entry.
  • Assemble and save all the prompt data to a JSON file.

This prompt data is the foundation for the LLM Prediction Game. In the next set of exercises, you’ll get hands-on practice generating and saving prompt data yourself. This will prepare you for the next steps in building the game. Good luck!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal