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

gptdocx

v1.0.4

Published

Create word documents with ChatGPT.

Downloads

14

Readme

GPTDocx

Create word documents with ChatGPT.

docxImage

gptdocx

gptdocx is an npm module designed to simplify the process of creating Word documents using the ChatGPT language model from OpenAI. With this module, you can easily generate dynamic and content-rich Word documents programmatically.

Description

Generating Word documents has never been easier. gptdocx leverages the power of ChatGPT to provide a seamless interface for creating documents with natural language inputs. Whether you need to draft reports, letters, or any textual content, this module streamlines the process, making it accessible through Node.js and TypeScript.

Requirements

Before using gptdocx, ensure that you have the following prerequisites:

  • Node.js: Make sure Node.js is installed on your system. You can download it here.

  • OpenAI API Key: Obtain an API key from OpenAI by creating an account and navigating to the OpenAI developer portal. Make sure there is a sufficient balance in your account to cover API usage.

  • .env File: Create a .env file at the root of your project and add your OpenAI API key using the following format:

    OPENAI_API_KEY=your_api_key_here
  • Files Directory: Create a files directory at the root of your current working directory. This directory will be used to store the generated Word documents.

Usage

  1. Install the gptdocx module:

    npm install gptdocx
  2. Import the module in your Node.js project:

    const gptdocx = require('gptdocx');
    // or
    import gptdocx from 'gptdocx';
  3. Use the GPTDocx object to generate Word documents:

    const { GPTDocx, BASIC } = gptdocx;
    
    const filePath = await new GPTDocx({
       format: BASIC, 
       prompt: "Write  Paper on coffee.",
     }).createFile();
  4. Run your Node.js script:

    node your_script.js

Running the code above will create a new word document in the files with context from ChatGPT on the subject coffee.

GPTDocx Object

The GPTDocx object uses Docx and DocxTemplater to build .docx files. If you configure format as an object, GPTDocx will use Docx to build the word document. This approach requires a little more overhead, but adds greater flexibility as you supply the format and style of the document yourself. However, if you use an exported format, GPTDocx will use Docxtemplater to build the document. Docxtemplater requires templates to map data to the word document. The formats exported from the gptdocx module tells the GPTDocx object what format and template to use in the request.

Example 1: Docxtemplater Approach

const gptdocx = require('gptdocx');

const { GPTDocx, SIMPLE } = gptdocx;

const filePath = await new GPTDocx({
    format: SIMPLE,
    prompt: "Write a paragraph.",
}).createFile();

In the example above, GPTDocx creates a word document using the SIMPLE format which corresponds to a template that GPTDocx can locate and use to build the document. No styling is needed as the is already predesigned with fonts, headings, etc.

Example 2: Docx Approach

  const filePath = await new GPTDocx({
    format: {
      sys: {
        format: "json",
        name: "demoFormat",
        values: {
          content: [
            {
              title: "",
              body: "",
            },
          ],
        },
      },
      styles: { // optional
        title: {
          paragraph: {
            heading: "Heading4",
            spacing: {
              before: 100,
              after: 10,
            },
          },
          text: {
            color: "#000000",
            bold: true,
          },
        },
        body: {
          paragraph: {
            spacing: {
              before: 100,
              after: 100,
            },
          },
          text: {
            color: "#333333",
          },
        },
      },
    },
    prompt: "Write a paper about Whales.",
  }).createFile();

In the example above, GPTDocx will send the prompt to ChatGPT with the property values for context. The styles object maps the Docx Styles to the properties in the values object. Nearly everything in Docx can be placed into a class Paragraph which can include a class TextRun, therefore, GPTDocx uses properties paragraph and text within styles and maps the styles to the respective classes. More Examples.

Contributing

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue on the GitHub repository. If you'd like to contribute directly, feel free to submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.