npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

quiz_builder_js

v0.0.1

Published

Generate quizes from PDFs, Text,and URLs using gpt. Saves as a .json file.

Downloads

2

Readme

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.