Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
glaucia86 opened this issue Feb 19, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@glaucia86
Copy link
Member

glaucia86 commented Feb 19, 2025

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.

@glaucia86 glaucia86 added the enhancement New feature or request label Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant