Riding the Wave of Effective AI Prompt Crafting

In this article, we'll take an in-depth look at the art of AI prompt creation, exploring a genuine technique that aids in the design of more robust and dependable prompts. We'll uncover the subtleties of prompt crafting through the RODES Prompt Framework created by @sebo_gm. Before we delve into the core of the subject, let's take a moment to get acquainted with what this framework entails.

The Framework

Creating an AI prompt can be likened to producing a film. It involves a cast (the AI), a script (the prompt), and the concluding scene (the output). The crucial part is to synchronise them all, and that's precisely where the RODES Framework steps in. It gives you a conceptual structure to make sure you include all the vital components when formulating your prompt.

Now let's look at the individual components of the RODES Framework:

  1. Role (R): Like a director who assigns roles to actors, you're going to assign a role to the AI. The more specific the character description, the better the output. Example: "You are my personal assistant, adept at managing schedules, setting reminders, and executing organisational tasks with precision."
  2. Objective (O): Here's where you establish the main plot. Be as clear as possible about the task at hand. Example: "Your objective is to organise my schedule for next week, ensuring there are no clashes and adequate rest periods are included."
  3. Details (D): In this component, you lay out the ground rules, defining what the task should and shouldn't include. Example: "The schedule must not have any overlapping appointments, should include a 1-hour lunch break each day, and must factor in two 15-minute rest breaks that are not back to back."
  4. Examples (E): Similar to how a director might show an actor a scene from a classic movie for inspiration, provide examples of what you want. This might include a sample of a well-organised schedule or a list of typical tasks. Example: "8-9 am: Breakfast & personal time. 9-11 am: Meeting with the Marketing team. 11-11:15 am: Break. 11:15 am-1 pm: Project work. 1-2 pm: Lunch. 2-3:30 pm: Emails and administrative tasks. 3:30-3:45 pm: Break. 3:45-5 pm: Meeting with Sales team. 5-6 pm: Wrap-up and planning for next day."
  5. Sense Check (S): Finally, perform a verification check with your AI component. Has it completely understood its function, objectives, and particular needs? This phase serves as a confirmation process, ensuring that the AI is fully equipped to move forward. If not, offer feedback to the user. For example: "If you do not understand your role as my personal assistant and the task of creating a well-structured schedule for my upcoming week? Respond requesting any additional information you need from me to complete this task more efficiently." This allows the AI to prompt for clarifications, ensuring a smoother execution of the tasks.

RODES in Action

You could utilize this framework when crafting your prompts for the ChatGPT client, but for those eager to get there hands a little more dirty, and see a more functional example, we will build a small Node.js script that organizes weekly tasks using OpenAI's GPT-3.5-turbo model. The script quickly organises tasks into a coherent weekly schedule.

Let's explore the details.

We'll start by breaking down the framework components into separate variables for ease of understanding and modification. This practice enhances readability and allows straightforward customisation as we fine tune the prompt to get the best result.

Here's the framework variables bit:

const role = "You are my personal assistant skilled in organising schedules, setting reminders, and managing time effectively.";

const objective = "Your objective is to organise these tasks into a weekly schedule ensuring no conflicts and ample rest time is included. spread tasks across the week to ensure a balanced schedule.";

const details = "The schedule should not have any overlapping appointments, must include a one-hour lunch break each day, should not allow for a work day greater than 9 hours and should also incorporate two 15-minute rest periods. No not include any tasks that are not listed in the task list.";

const examples = `Example schedule:
- Monday: 
    8-9am: Breakfast & personal time. 
    9-11am: Meeting with Marketing team. 
    11-11:15am: Break. 
    11:15am-1pm: Project work. 
    1-2pm: Lunch. 
    2-3:30pm: Emails and administrative tasks. 
    3:30-3:45pm: Break. 
    3:45-5pm: Meeting with Sales team. 
    5-6pm: Wrap-up and planning for the next day.
- Tuesday: 
    ... (similar structure).
- Wednesday: 
    ... (similar structure).
... (and so on for the rest of the week).`;

const senseCheck = "If you do not understand your role as my personal assistant and the task of creating a well-structured schedule for my upcoming week? Respond requesting any additional information you need from me to complete this task more efficiently.";

Then, we make the call to OpenAI to do the work, using two roles within the message context:

  1. System Role: This is where the RODES framework is utilised. The system role combines all of the RODES components with the tasks, creating the overall instruction for the AI. It sets the context and instructs the AI on what to do.
  2. User Role: This role provides the tasks that need to be organised into a weekly schedule. It's the additional user input for the AI to act upon based on the instructions provided in the system role.

Finally, we console.log the result for the user.

The full code and everything you need to know to get it running can be found in my GitHub repository:https://github.com/levi-putna/RODES-Framework-Example

For convenience, here's the main script we will be talking about:

require('dotenv').config(); // Load environment variables
const { Configuration, OpenAIApi } = require("openai");

// Using RODES framework (Role, Objective, Details, Examples, Sense Check)

// ROLE (R): Assigning a role to the AI for the task.
const role = "You are my personal assistant skilled in organising schedules, setting reminders, and managing time effectively.";

// OBJECTIVE (O): Establishing the main plot, what the AI needs to achieve.
const objective = "Your objective is to organise these tasks into a weekly schedule including Monday, Tuesday, Wednesday, Thursday and Friday ensuring no conflicts and ample rest time is included.";

// DETAILS (D): Laying out ground rules for the task.
const details = "The schedule should not have any overlapping appointments, must include a one-hour lunch break each day, should not allow for a work day greater than 9 hours and should also incorporate two 15-minute rest periods. Try to spread tasks evenly across the week to ensure a balanced schedule. Do not include any tasks that are not listed in the task list.";

// EXAMPLES (E): Providing examples to guide the AI in what is needed.
const examples = `Example schedule:
- Monday: 
    8-9am: Breakfast & personal time. 
    9-11am: Meeting with Marketing team. 
    11-11:15am: Break. 
    11:15am-1pm: Project work. 
    1-2pm: Lunch. 
    2-3:30pm: Emails and administrative tasks. 
    3:30-3:45pm: Break. 
    3:45-5pm: Meeting with Sales team. 
    5-6pm: Wrap-up and planning for the next day.
- Tuesday: 
    ... (similar structure).
- Wednesday: 
    ... (similar structure).
- Thursday: 
    ... (similar structure).
- Friday: 
    ... (similar structure).`;

// SENSE CHECK (S): Asking the AI if it fully comprehends its role, goals, and requirements.
const senseCheck = "If you do not understand your role as my personal assistant and the task of creating a well-structured schedule for my upcoming week? Respond requesting any additional information you need from me to complete this task more efficiently.";

// Accept the tasks as a command-line argument in the format "task:time"
const tasksArg = process.argv[2];
// If time allotment is not given, default to 30 min
let tasks = tasksArg.split(',').map(task => {
    let [taskName, time] = task.split(':');
    if (!time) {
        time = '30 min';
    }
    return `${taskName}(${time})`;
}).join(', ');

const tasksList = `Tasks: ${tasks}`;

(async () => {
    // Create OpenAI configuration
    const configuration = new Configuration({
        apiKey: process.env.OPENAI_API_KEY,
    });

    // Create OpenAI instance
    const openai = new OpenAIApi(configuration);

    console.log(`Whipping up your schedule! Hang tight, it's almost ready 📅\n`);

    // Call OpenAI API to create the schedule based on RODES framework
    const response = await openai.createChatCompletion({
        model: "gpt-4-0613",//updated from gpt-3.5-turbo-0613 as gpt-4 follows system roles better
        'messages': [
            { 'role': 'system', 'content': `${role}\n${objective}\n${details}\n${examples}\n${senseCheck}\n${tasksList}` },
            { 'role': 'user', 'content': `Organise these tasks into a weekly schedule: ${tasks}` }
        ],
        temperature: 0.5,
        max_tokens: 500,
        top_p: 1,
        frequency_penalty: 0.0,
        presence_penalty: 0.0,
    });

    // Retrieve content and function call from API response
    const { content } = response.data.choices[0].message;

    console.log(content + '\n');
    
})();

Running the Script

With everything set up, it's time to put the script to the test! Here's how you can run the script using an example input.

Command Line Input

Open a terminal and navigate to the directory where your script is located. Then, run the following command:

node index.js "Meeting with Marketing team,120; Project work,90; Lunch with Client,60; Sales Review,30; Team Building Activity,180; Strategy Planning,120; Review Emails,45; Finalise Quarterly Report,75"

Expected Output

The script will take the provided tasks, each with its own time allotment in minutes, and organise them into a well-balanced weekly schedule. It follows the rules outlined in the "details" section, so you can expect to see a schedule like the following:

  • Non-overlapping appointments
  • A one-hour lunch break each day
  • Workdays no longer than 9 hours
  • Two 15-minute rest periods per day

Here's a snippet of what the output might look like:

Whipping up your schedule! Hang tight, it's almost ready 📅

Here is your organized weekly schedule:

- Monday:
    8-9am: Breakfast & personal time.
    9-11am: Project work.
    11-11:15am: Break.
    11:15am-1:15pm: Meeting with Marketing team.
    1:15-2:15pm: Lunch.
    2:15-3:45pm: Review Emails.
    3:45-4pm: Break.
    4-5pm: Sales Review.
    5-6pm: Wrap-up and planning for the next day.

- Tuesday:
    8-9am: Breakfast & personal time.
    9-11am: Strategy Planning.
    11-11:15am: Break.
    11:15am-1:15pm: Project work.
    1:15-2:15pm: Lunch with Client.
    2:15-3:45pm: Finalize Quarterly Report.
    3:45-4pm: Break.
    4-6pm: Wrap-up and planning for the next day.

- Wednesday:
    8-9am: Breakfast & personal time.
    9-11am: Strategy Planning.
    11-11:15am: Break.
    11:15am-1:15pm: Meeting with Marketing team.
    1:15-2:15pm: Lunch.
    2:15-3:45pm: Review Emails.
    3:45-4pm: Break.
    4-6pm: Wrap-up and planning for the next day.

- Thursday:
    8-9am: Breakfast & personal time.
    9-11am: Project work.
    11-11:15am: Break.
    11:15am-1:15pm: Finalize Quarterly Report.
    1:15-2:15pm: Lunch with Client.
    2:15-3:45pm: Sales Review.
    3:45-4pm: Break.
    4-6pm: Wrap-up and planning for the next day.

- Friday:
    8-9am: Breakfast & personal time.
    9-12pm: Team Building Activity

Error Handling

Finally let's look at the sense check in more detail, this effectively acts as our input validation, checking that there is enough information provided to produce an output. If bad informations provided, then this will inform the AI to respond with a useful clarification.

Open a terminal and navigate to the directory where your script is located. Then, run the following command:

node index.js "this is a bad param"

And we should see an output similar to:

I'm sorry, but the task you've provided "this is a bad param" is unclear. Could you provide more details or specify what tasks need to be scheduled? For example, you could list tasks such as meetings, project work, administrative tasks, etc. Once I have more information, I'll be able to help organise your schedule more efficiently.

Conclusion

The RODES Framework equips you with a mental structure to comprehensively analyse and consider all the elements of your prompt. By breaking down the various components and providing a systematic approach, it ensures that the prompt creation process is well-considered and consistent. This method offers a clear pathway for thinking through each aspect, making it an invaluable tool for constructing effective and well thought out prompts.

Again, credit to @sebo_gm for sharing his prompt framework.

You've successfully subscribed to Twisted Brackets
Great! Next, complete checkout to get full access to all premium content.
Error! Could not sign up. invalid link.
Welcome back! You've successfully signed in.
Error! Could not sign in. Please try again.
Success! Your account is fully activated, you now have access to all content.
Error! Stripe checkout failed.
Success! Your billing info is updated.
Error! Billing info update failed.