Skip to content

Commit b1146c5

Browse files
authored
Merge pull request #2 from gmickel:add-prompt-generation
feat: question creator prompt
2 parents a92ad20 + 3735448 commit b1146c5

File tree

4 files changed

+157
-3
lines changed

4 files changed

+157
-3
lines changed

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Welcome to CodeQuest, the quiz game that's more addictive than trying to fix a b
1515
- 🎊 **Confetti**: Celebrate your achievements with a rainbow of confetti!
1616
- 🏆 **Score Sharing**: Brag about your big brain energy on social media
1717
- 📱 **Responsive Design**: Looks great on everything from your smartwatch to your smart fridge
18+
- 🧙‍♂️ **Question Generation**: Generate question creation prompts to use with your favorite LLM!
1819

1920
## 🎭 Question Features (The Real Stars of the Show)
2021

@@ -29,6 +30,35 @@ Welcome to CodeQuest, the quiz game that's more addictive than trying to fix a b
2930

3031
Check out `example-question.md` for a comprehensive example of all these features in action!
3132

33+
## 🧙‍♂️ Question Generation (Let AI Do the Heavy Lifting)
34+
35+
Too busy debugging to craft questions? Fear not! We've conjured up a magical script to help you generate question prompts faster than you can say "Stack Overflow":
36+
37+
1. Wave your wand (or just type in your terminal):
38+
```
39+
bun run question-prompt
40+
```
41+
42+
2. Answer the mystical prompt asking how many questions you desire (choose wisely, young wizard!)
43+
44+
3. Behold as a perfectly crafted prompt materializes before your eyes!
45+
46+
4. Feed this prompt to your favorite AI familiar (we recommend Claude 3.5 Sonnet or GPT-4o for best results) and watch in awe as it conjures up quiz questions that would make even Merlin jealous.
47+
48+
5. Copy the AI-generated questions into new `.md` files in your `src/questions/` directory, and voilà! Your quiz just got a whole lot smarter.
49+
50+
Want to save your prompt for later? Use the `-o` flag:
51+
```
52+
bun run question-prompt -o prompt.md
53+
```
54+
55+
Need a helping hand? Just ask:
56+
```
57+
bun run question-prompt -h
58+
```
59+
60+
Remember, with great power comes great responsibility. Use this feature wisely, and may your questions be ever engaging and your quizzes eternally awesome! 🧙‍♂️✨
61+
3262
## 🚀 Quick Start Guide (No Rocket Science Degree Required)
3363

3464
1. Clone this repo:

bun.lockb

11.3 KB
Binary file not shown.

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"build": "tsc -b && vite build",
1717
"lint": "eslint .",
1818
"lint:fix": "eslint . --fix",
19-
"preview": "vite preview"
19+
"preview": "vite preview",
20+
"question-prompt": "node question-prompt.cjs"
2021
},
2122
"dependencies": {
2223
"@radix-ui/react-alert-dialog": "1.1.1",
@@ -28,22 +29,24 @@
2829
"clsx": "2.1.1",
2930
"gray-matter": "^4.0.3",
3031
"lucide-react": "0.408.0",
31-
"marked": "^13.0.2",
32+
"marked": "13.0.2",
3233
"react": "18.3.1",
3334
"react-confetti": "6.1.0",
3435
"react-dom": "18.3.1",
3536
"shiki": "1.10.3",
3637
"tailwind-merge": "2.4.0",
3738
"tailwindcss-animate": "1.0.7",
38-
"yaml": "^2.4.5"
39+
"yaml": "2.4.5"
3940
},
4041
"devDependencies": {
4142
"@antfu/eslint-config": "2.23.0",
43+
"@inquirer/prompts": "5.2.0",
4244
"@types/node": "20.14.11",
4345
"@types/react": "18.3.3",
4446
"@types/react-dom": "18.3.0",
4547
"@vitejs/plugin-react": "4.3.1",
4648
"autoprefixer": "10.4.19",
49+
"commander": "12.1.0",
4750
"eslint": "9.7.0",
4851
"postcss": "8.4.39",
4952
"tailwindcss": "3.4.6",

question-prompt.cjs

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
const fs = require('node:fs').promises;
2+
const path = require('node:path');
3+
const process = require('node:process');
4+
const { program } = require('commander');
5+
const { number } = require('@inquirer/prompts');
6+
7+
async function readFiles(dir) {
8+
const files = await fs.readdir(dir);
9+
return Promise.all(
10+
files.map(async (file) => {
11+
const content = await fs.readFile(path.join(dir, file), 'utf8');
12+
return { name: file, content };
13+
}),
14+
);
15+
}
16+
17+
async function generatePrompt(numQuestions) {
18+
try {
19+
const questionsDir = path.join(__dirname, 'src', 'questions');
20+
const existingQuestions = await readFiles(questionsDir);
21+
const exampleQuestion = await fs.readFile(path.join(__dirname, 'example-question.md'), 'utf8');
22+
23+
return `
24+
You are an expert quiz creator for the CodeQuest project. Your task is to create ${numQuestions} new question(s) for our fun, engaging and playful quiz game. Here are the guidelines:
25+
26+
1. Each question should be in Markdown format, similar to the example provided below.
27+
2. Questions should increase in difficulty as they progress.
28+
3. The title and description should be fun, descriptive and engaging. Use alliterations and wordplay to make them stand out.
29+
3. Use the following features where appropriate:
30+
- Markdown formatting (bold, italics, code blocks, lists etc.)
31+
- Multiple choice answers
32+
- Time limits (optional)
33+
- Difficulty levels (Beginner, Intermediate, Expert) (optional)
34+
- Hints
35+
- Explanations
36+
37+
4. The structure should be exactly as follows:
38+
---
39+
title: [Question Title]
40+
description: [Brief description]
41+
level: [number, determines order]
42+
correctAnswer: [number, 1-based index of correct answer]
43+
difficulty: [Beginner/Intermediate/Expert]
44+
timeLimit: [optional, in seconds]
45+
---
46+
47+
## Context
48+
49+
### Introduction
50+
[Optional: Only include if necessary to understand the question]
51+
52+
### Question
53+
[The actual question goes here]
54+
55+
### Outro
56+
[Optional: Include only to provide additional resources or information]
57+
58+
## Answers
59+
- [Answer option 1]
60+
- [Answer option 2]
61+
- [Answer option 3]
62+
- [Answer option 4]
63+
64+
## Explanation
65+
[Detailed explanation of the correct answer]
66+
67+
## Hint
68+
[Optional hint for the question]
69+
70+
5. Prefer short answer options, but use code fences for longer code snippets if necessary.
71+
6. Ensure questions are relevant to coding, technology, or related fields.
72+
7. Be creative and make the questions engaging!
73+
74+
Here's an example question for reference:
75+
76+
${exampleQuestion}
77+
78+
Now, based on the existing questions and this example, please create ${numQuestions} new question(s). Ensure they fit well with the existing set and increase in difficulty appropriately.
79+
80+
Existing questions for context:
81+
${existingQuestions.map(q => q.content).join('\n\n')}
82+
`;
83+
}
84+
catch (error) {
85+
console.error('Error generating prompt:', error);
86+
}
87+
}
88+
89+
async function main() {
90+
program
91+
.option('-o, --output <file>', 'output file')
92+
.helpOption('-h, --help', 'display help for command')
93+
.parse(process.argv);
94+
95+
const options = program.opts();
96+
97+
if (options.help) {
98+
program.outputHelp();
99+
process.exit(0);
100+
}
101+
102+
try {
103+
const numQuestions = await number({ message: 'How many questions do you want to generate?' }, { min: 1, max: 5 });
104+
const prompt = await generatePrompt(numQuestions);
105+
106+
if (options.output) {
107+
await fs.writeFile(options.output, prompt);
108+
// eslint-disable-next-line no-console
109+
console.log(`Prompt written to ${options.output}`);
110+
}
111+
else {
112+
process.stdout.write(prompt);
113+
}
114+
}
115+
catch (error) {
116+
console.error('An error occurred:', error);
117+
process.exit(1);
118+
}
119+
}
120+
121+
main();

0 commit comments

Comments
 (0)