microsoft / microsoft/generative-ai-with-javascript

feat/idea: implementing an Easter Egg in Lesson 02 – First AI App (`sample-app/app.js`)

Open
#26 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
1.3k
Forks
841
Avg merge
1d 3h
Merged PRs (30d)
1

Description

Path: lessons/02-first-ai-app/sample-app/app.js

The goal of this Easter Egg is to allow users to discover a secret response when they input a specific phrase into the code.
In this case, we’ll add a “special prompt” that, when detected, unlocks a hidden secret about time travel.

💡 How Will the Easter Egg Work?

  • If the user changes the question variable to "Open the hidden gates", the code will reveal a hidden message in the console.
  • The user will then be redirected to a special link with more content on AI and JavaScript.

🛠 Steps for Implementation

📂 File: lessons/02-first-ai-app/sample-app/app.js

🔹 Updated Code with the Easter Egg:
import { OpenAI } from "openai";

// 1. Define the prompt
// -----------------------------------

const question = "Tell me about where I am";

const messages = [
  {
    "role": "system",
    "content": "You're a helpful assistant that will only answer questions about Florence in the 1400s"
  },
  {
    "role": "user",
    "content": question
  }
];

// 2. Create client
// -----------------------------------

const openai = new OpenAI({
  baseURL: "https://models.inference.ai.azure.com",
  apiKey: process.env.GITHUB_TOKEN,
});

// 3. Send the request
// -----------------------------------

const completion = await openai.chat.completions.create({
  model: 'gpt-4o-mini',
  messages: messages,
});

console.log(`Answer for "${question}":`);
console.log(completion.choices[0]?.message?.content);

// 🕵️ Easter Egg: Secret AI Message 🕵️
// -----------------------------------
if (question.toLowerCase() === "open the hidden gates") {
  console.log("\n✨ You have unlocked a hidden AI secret! 🚀");
  console.log("🔗 Check out this exclusive resource: https://aka.ms/Secret-AI-JS");
  console.log("\n🔍 Fun Fact: The first concept of time travel appeared in literature in 1888!");
}


📌 Explanation of the Code

1️⃣ Detects if the user changes the question variable to "Open the hidden gates"

  • The code checks if question.toLowerCase() matches the Easter Egg trigger.

2️⃣ If the user enters this prompt, a secret message will be displayed in the console:

  • "✨ You have unlocked a hidden AI secret! 🚀"
  • "🔗 Check out this exclusive resource: https://aka.ms/Secret-AI-JS" (this link should be pre-created with special content).
  • "🔍 Fun Fact: The first concept of time travel appeared in literature in 1888!"

Impact:

  • Encourages users to explore and modify the code.
  • Demonstrates how different prompts can affect AI behavior.
  • Adds a fun surprise, making learning more engaging.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open lessons/02-first-ai-app/sample-app/app.js and review the existing question handling and console output, then run the sample app with the stated prompt. Done means the specified phrase produces the hidden time-travel message and resource link in the console without affecting the normal response.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
ai
Issue type
Feature
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.