Skip to content

Commit c9b8495

Browse files
feat: Add Easter Egg detection for optimized prompts (Issue #27)
1 parent 69c2d8f commit c9b8495

File tree

1 file changed

+28
-37
lines changed
  • lessons/03-prompt-engineering/sample-app

1 file changed

+28
-37
lines changed
Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { OpenAI } from "openai";
22
import readline from "readline";
33

4+
// User input
45
const rl = readline.createInterface({
56
input: process.stdin,
67
output: process.stdout
@@ -14,48 +15,38 @@ const question = (query) => {
1415
});
1516
};
1617

17-
const height = await question("Enter the current height above the ground in meters:");
18+
async function main() {
19+
const userPrompt = await question("Enter your prompt: ");
1820

19-
const speed = await question("Enter the speed at which you're moving forward in meters per second:");
21+
const messages = [
22+
{
23+
role: "user",
24+
content: userPrompt
25+
}
26+
];
2027

21-
const gravity = await question("Enter the gravity in meters per second squared:");
22-
23-
const wind = await question("Enter the wind speed upwards in meters per second:");
24-
25-
// Distance to the hill
26-
const distance = 100;
27-
28-
// Create prompt including inputs should include chain of thought
29-
30-
const prompt = "TODO";
31-
32-
// Call the language model with the prompt
33-
34-
const messages = [
35-
{
36-
"role": "user",
37-
"content": prompt
38-
}];
39-
40-
// 2. Create client
41-
// -----------------------------------
42-
43-
const openai = new OpenAI({
44-
baseURL: "https://models.inference.ai.azure.com",
45-
apiKey: process.env.GITHUB_TOKEN,
46-
});
47-
48-
// 3. Send the request
49-
// -----------------------------------
28+
// OpenAI API setup
29+
const openai = new OpenAI({
30+
baseURL: "https://models.inference.ai.azure.com",
31+
apiKey: process.env.GITHUB_TOKEN,
32+
});
5033

51-
const completion = await openai.chat.completions.create({
34+
const completion = await openai.chat.completions.create({
5235
model: 'gpt-4o-mini',
5336
messages: messages,
54-
});
37+
});
38+
39+
const answer = completion.choices[0]?.message?.content;
40+
41+
console.log(`\nAI Response:\n`);
42+
console.log(answer);
5543

56-
console.log(`Answer for "${prompt}":`);
44+
// Easter Egg Check
45+
if (userPrompt.toLowerCase().includes("time-traveling javascript developer") && answer) {
46+
console.log("\n Easter Egg Unlocked! You discovered the hidden poem! ");
47+
}
5748

58-
// 4. Print the answer
59-
// -----------------------------------
49+
rl.close();
50+
}
6051

61-
console.log(completion.choices[0]?.message?.content);
52+
main();

0 commit comments

Comments
 (0)