From c9b849506147fdee40c79ac4fab09c9e3824a628 Mon Sep 17 00:00:00 2001 From: Dhrubaraj Pati Date: Fri, 2 May 2025 10:31:38 +0530 Subject: [PATCH] feat: Add Easter Egg detection for optimized prompts (Issue #27) --- .../03-prompt-engineering/sample-app/app.js | 65 ++++++++----------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/lessons/03-prompt-engineering/sample-app/app.js b/lessons/03-prompt-engineering/sample-app/app.js index c277e1b..5c4c74e 100644 --- a/lessons/03-prompt-engineering/sample-app/app.js +++ b/lessons/03-prompt-engineering/sample-app/app.js @@ -1,6 +1,7 @@ import { OpenAI } from "openai"; import readline from "readline"; +// User input const rl = readline.createInterface({ input: process.stdin, output: process.stdout @@ -14,48 +15,38 @@ const question = (query) => { }); }; -const height = await question("Enter the current height above the ground in meters:"); +async function main() { + const userPrompt = await question("Enter your prompt: "); -const speed = await question("Enter the speed at which you're moving forward in meters per second:"); + const messages = [ + { + role: "user", + content: userPrompt + } + ]; -const gravity = await question("Enter the gravity in meters per second squared:"); - -const wind = await question("Enter the wind speed upwards in meters per second:"); - -// Distance to the hill -const distance = 100; - -// Create prompt including inputs should include chain of thought - -const prompt = "TODO"; - -// Call the language model with the prompt - -const messages = [ -{ - "role": "user", - "content": prompt -}]; - -// 2. Create client -// ----------------------------------- - -const openai = new OpenAI({ - baseURL: "https://models.inference.ai.azure.com", - apiKey: process.env.GITHUB_TOKEN, -}); - -// 3. Send the request -// ----------------------------------- + // OpenAI API setup + const openai = new OpenAI({ + baseURL: "https://models.inference.ai.azure.com", + apiKey: process.env.GITHUB_TOKEN, + }); -const completion = await openai.chat.completions.create({ + const completion = await openai.chat.completions.create({ model: 'gpt-4o-mini', messages: messages, -}); + }); + + const answer = completion.choices[0]?.message?.content; + + console.log(`\nAI Response:\n`); + console.log(answer); -console.log(`Answer for "${prompt}":`); + // Easter Egg Check + if (userPrompt.toLowerCase().includes("time-traveling javascript developer") && answer) { + console.log("\n Easter Egg Unlocked! You discovered the hidden poem! "); + } -// 4. Print the answer -// ----------------------------------- + rl.close(); +} -console.log(completion.choices[0]?.message?.content); +main();