0.0.1 • Published 9 months ago

quiz_builder_js v0.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

quiz_builder_js

Includes a script 'quizai.js' as well as a starter 'api.js.' Enables you to generate quizes based of of:

  • Web Content - use the '--url' flag to specify what page to scrape content from.
  • PDFs - use the '--ifile' flag to specify an input file, automatically uses OCR to read text from pdfs, other extensions are read as raw text.
  • Text = use the '--text' flag to directly enter text to use as source material for your quiz.

Output

Unless the '--ofile' flag is specified, the quiz result will be logged to the console.

Usage

  1. You must have your own OpenAI API Key to take advantage of this library. Open 'config.example.json' and enter your API key where prompted. Then rename the file to config.json (remove example between). Visit OpenAI to get your own API key.
  2. Ensure all dependencies are installed by running npm install in the root directory.

Script

node quizai [...arguments]

Possible Arguments Include

  • --url: The url of the webpage to scrape text from.
  • --text: Text to use as input for quiz generation.
  • --ifile: The path to a file containing the input text. Supported file types include plain text, markdown, rtf, json and PDF files.
  • --ofile: Optional. The path to the output file where the generated quiz data will be saved in JSON format.
  • -c: Optional. Add this flag to enable the "usingCorrectionAi" feature. Please note that this is an experimental feature and may cause high usage of OpenAI tokens, and is not guarenteed to be 100% accurate.

API Documentation In Progress 🛠️:

Description:

This API provides endpoints to generate quiz questions based on text content extracted from web pages, provided text, or PDF files. It utilizes the Express framework for handling HTTP requests, and the API relies on utility functions (scrapePageText, quizCompletion, and extractPDFTextBuffer) defined in the ./utils module to process the data and generate quiz questions.

Base URL:

Assuming the server is running on http://your-api-domain.com, the base URL for this API would be:

  • http://your-api-domain.com/api/v1/

Endpoints:

1. Generate Quiz from Web Page:
  • URL: /api/v1/json/web
  • Method: POST
  • Request Body: JSON Object
    • url (string): The URL of the web page from which the content will be scraped to generate the quiz.
  • Response:
    • Success (200 OK): JSON Object
      • data: An array containing the generated quiz questions.
    • Error (400 Bad Request): JSON Object
      • error: Error message describing the issue.
Example:

Request: POST http://your-api-domain.com/api/v1/json/web {"url": "http://example.com"}

Response (200 OK):

[
  {
    "question": "GPT Generated Question",
    "options": [
        "Option 1",
        "Option 2",
        "Option 3",
        "Option 4",
    ],
    "answer": 0,
    "explaination": "Reasoning for the correct answer",
  },
  ...
]

2. Generate Quiz from Provided Text:

  • URL: /api/v1/json/text
  • Method: POST
  • Request Body: JSON Object
    • text (string): The input text from which the quiz questions will be generated.
  • Response:
    • Success (200 OK): JSON Object
      • data: An array containing the generated quiz questions.
    • Error (400 Bad Request): JSON Object
      • error: Error message describing the issue.
Example:

POST http://your-api-domain.com/api/v1/json/text

{
  "text": "The quick brown fox jumps over the lazy dog."
}

Response (200 OK):

[
  {
    "question": "GPT Generated Question",
    "options": [
        "Option 1",
        "Option 2",
        "Option 3",
        "Option 4",
    ],
    "answer": 0,
    "explaination": "Reasoning for the correct answer",
  },
  ...
]

3. Convert PDF and Generate Quiz:

  • URL: /api/v1/pdfs/convert
  • Method: POST
  • Request Body: PDF file data (Raw binary data, max limit 10 MB)
  • Response:
    • Success (200 OK): JSON Object
      • data: An array containing the generated quiz questions.
    • Error (400 Bad Request): JSON Object
      • error: Error message describing the issue.
Example:

POST http://your-api-domain.com/api/v1/pdfs/convert

  • PDF file binary data as the request body

Response (200 OK):

[
   {
    "question": "GPT Generated Question",
    "options": [
        "Option 1",
        "Option 2",
        "Option 3",
        "Option 4",
    ],
    "answer": 0,
    "explaination": "Reasoning for the correct answer",
  },
  ...
]

Error Handling:

  • If any errors occur during the API requests, the server will respond with a JSON object containing an "error" field that describes the issue.
  • HTTP status code 400 will be used for errors, indicating a bad request.

Dependencies:

  • The API relies on the express library to handle HTTP requests and routing.

Usage:

  • Ensure that the API server is running, and the ./utils module is properly implemented with the required utility functions (scrapePageText, quizCompletion, and extractPDFTextBuffer) to support the API endpoints.
  • You can use this API to automate the process of generating quiz questions from web pages, text data, or PDF files.

Note:

  • For production deployment, ensure proper security measures, input validation, and error handling are implemented. This documentation is a basic reference and may require further enhancements depending on your specific use case.

Use API with Your Project

    const {api} = require("quiz_builder_js/api")
    api.listen(8080, ()=>console.log("Running on port 8080"))
  • note that api is just an express() app, so you can add routes as desired.