This project implements an AI-enabled quiz app where students can take a quiz to test their knowledge with AI-generated multiple-choice questions. The app supports creating quizzes, presenting questions, submitting answers, and showing results.
Though the instructions said I could complete this in the language or framework I'm most comfortable with, I chose to use Ruby on Rails for the backend and React for the frontend. This choice was made to leverage my existing knowledge of these technologies and to create a robust and maintainable application. Additionally, I'm aware that QuantHub uses these technologies.
Though I'm applying for a leadership role, I hope this project demonstrates my technical skills and thought process. I believe that a strong technical foundation is essential for effective leadership in software development.
- AI-Generated Multiple Choice Questions: Questions are dynamically generated using OpenAI's GPT-3.5-turbo model. Each question includes multiple options, with one correct answer.
- Quiz Progression: The quiz ends after 3 responses, and a final score is provided (don't miss the surprise if you score a 60 or above!)
- AI Integration: A standard model (OpenAI's GPT-3.5-turbo) is used to generate questions dynamically.
- Retries: There is no retries or ability to skip or change answers.
My approach to this challenge was guided by the maxim: "1. Make it work. 2. Make it right. 3. Make it fast." This allowed me to prioritize delivering a functional app first, refining its structure and design second, and optimizing its implementation for performance and delight last. Below are the steps I followed:
- Carefully reviewed the challenge instructions to understand the core functionality required.
- Identified the primary user stories:
- Presenting AI-generated multiple-choice questions.
- Submitting responses and grading them instantly.
- Completing the quiz after a number of questions and providing scores.
- Created additional scenarios for the quiz lifecycle to ensure clarity. These scenarios helped guide the development process and ensured that the app's behavior aligned with the requirements.
- Sketched a high-level design of the application.
Home:
- Should display welcome text
- Should have button to start quiz
Quiz:
- Should display the question number
- Should display the current question
- Should display the next question after submitting the answer to the current question (results shown at end of game)
Results:
- Should display a score comprised of correct answers and total answers
- Should display a list of the questions and whether the answer was correct or not
- Should allow the user to start over
- Initialized a new Rails project.
- Installed and setup Inertia and React.
- Scaffold models, views, and controllers.
- Built the core functionality.
- Focused on "making it work" by ensuring all functionality was correct and met the user stories.
- Corrected bugs found during manual testing.
- Integrated ruby-openai for dynamic question generation:
- Designed a robust prompt for generating valid multiple-choice questions.
- Validated the structure of AI-generated questions before including them in the quiz.
- Added error handling to fallback to static questions if the AI response was invalid or unavailable.
By following the principle of "Make it work. Make it right. Make it fast," I focused on delivering a working solution first, refining its structure and logic second, and leaving performance tuning and gold-plating for final touches.
-
AI Integration:
- Challenge: Ensuring consistent and valid output from OpenAI for questions.
- Decision: Structured prompts and robust error handling for fallback questions.
-
Limited Time:
- Challenge: Balancing between feature completeness and code quality within the suggested 1-2 hours.
- Decision: Focused on core functionality with a clear, extensible structure.
-
Error Handling:
- Challenge: Handling cases where AI fails to generate valid questions.
- Decision: Added static fallback questions to ensure resilience.
-
Linear Quiz Progression:
- Challenge: Users could navigate back to previous or future questions. Users could load completed quiz and change answers.
- Decision: Added various checks and redirects. I'd prefer to utilize a finite state machine if given more time.
-
Clone the Repository:
git clone git@github.com:devanb/ai-quiz.git cd ai-quiz -
Install Dependencies:
bundle install
-
Setup Environment Variables:
-
Create a
.envfile in the project root:OPENAI_API_KEY=your_openai_api_key
-
Replace
your_openai_api_keywith your actual OpenAI API key.
-
-
Run Database Migrations:
rails db:create db:migrate
-
Start the app:
bin/dev
-
Access the app:
- The app will be available at
http://localhost:3100.
- The app will be available at
If I had more time, I would:
-
Testing and CI/CD:
- Write comprehensive unit tests and add E2E tests for major code paths.
- Setup CI/CD pipelines for automated testing.
-
User Experience and Features:
- Add authentication and scope quizzes to users.
- Add support for question categories, number of questions, and varying difficulty levels.
- Add ability to review and edit answers before submitting quiz for grading.
- Use AI to provide detailed explanations for incorrect answers.
-
Technical Improvements:
- Implement finite state machine for managing quiz states and extended data flow.
- Add code-splitting for minute performance improvements.
- Add more robust error handling and logging.
- Add more robust handling of AI issues (e.g., rate limits, timeouts, etc.).
Thanks for reviewing my submission! I enjoyed sprinting on this project and would love to discuss it further.