Skip to content

feat: Add Easter Egg detection for optimized prompts (Issue #27) #114

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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 28 additions & 37 deletions lessons/03-prompt-engineering/sample-app/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { OpenAI } from "openai";
import readline from "readline";

// User input
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
Expand All @@ -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();