DevanB / ai-quiz

Repository from Github https://github.comDevanB/ai-quizRepository from Github https://github.comDevanB/ai-quiz

AI Quiz

Overview

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.


Features

  • 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!)

Assumptions

  • 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.

Process

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:

1. Analyzing Requirements

  • 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.

2. Create Additional Functionality Statements and Design

  • 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

3. Project Instantiation

  • Initialized a new Rails project.
  • Installed and setup Inertia and React.
  • Scaffold models, views, and controllers.

4. Complete Basic Quiz Functionality

  • 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.

5. Add AI-Generated Questions

  • 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.


Challenges and Decisions

  1. AI Integration:

    • Challenge: Ensuring consistent and valid output from OpenAI for questions.
    • Decision: Structured prompts and robust error handling for fallback questions.
  2. 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.
  3. Error Handling:

    • Challenge: Handling cases where AI fails to generate valid questions.
    • Decision: Added static fallback questions to ensure resilience.
  4. 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.

Installation and Setup

Prerequisites

  • Ruby (app built with 3.2.3)
  • Rails (app built with 8.0.2)
  • OpenAI API Key for integration

Steps to Run the Project

  1. Clone the Repository:

    git clone git@github.com:devanb/ai-quiz.git
    cd ai-quiz
  2. Install Dependencies:

    bundle install
  3. Setup Environment Variables:

    • Create a .env file in the project root:

      OPENAI_API_KEY=your_openai_api_key
    • Replace your_openai_api_key with your actual OpenAI API key.

  4. Run Database Migrations:

    rails db:create db:migrate
  5. Start the app:

    bin/dev
  6. Access the app:

    • The app will be available at http://localhost:3100.

Next Steps

If I had more time, I would:

  1. Testing and CI/CD:

    • Write comprehensive unit tests and add E2E tests for major code paths.
    • Setup CI/CD pipelines for automated testing.
  2. 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.
  3. 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.).

Thank You

Thanks for reviewing my submission! I enjoyed sprinting on this project and would love to discuss it further.

About


Languages

Language:Ruby 42.8%Language:HTML 32.3%Language:TypeScript 12.8%Language:CSS 6.2%Language:Shell 2.3%Language:Dockerfile 2.1%Language:JavaScript 1.6%