New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

format-gpt2

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

format-gpt2

ChatGPT output formatter.

  • 1.0.0
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source
Albuquerque, New Mexico Sanitize ChatGPT output and format it the way you want!

FormatGPT is a robust library designed to sanitize output provided by ChatGPT. It provides a consistent and well defined method for retrieving the data from ChatGPT by acting as a middle man between your code and ChatGPT API. It supports various formats such as:

  • text
  • json
  • json-list
  • csv
  • html
  • markdown
  • arrays
  • tables
  • xml
  • yaml

Additionally each output format can be easily customized to suit your needs.

Table of Contents

  1. Installation
  2. Usage
  3. API Reference
  4. Building
  5. Tests
  6. License

Installation

To install the library using npm run the command:

npm install format-gpt

To install the library using yarn run the command:

yarn add format-gpt

Usage

Here's a quick example to get you started:

import formatGPT from "format-gpt";

formatGpt.format({
	format: "json",
	options: {
		attributes: [
			{ name: "name", type: "string" },
			{ name: "description", type: "string", maxLength: 200 },
			{ name: "released", type: "date" },
			{ name: "price", type: "decimal" }
		]
	},
	language: "en"
});

API Reference

The default export is formatChatGptPrompt.

formatChatGptPrompt
formatChatGptPrompt({
  prompt: string,
  format: Format,
  options?: FormatOptions,
  language?: string
}): string;
props
  • prompt (string) - content of the prompt for chat-gpt
  • format (Format) - format in which to return output from chat-gpt
  • options (FormatOptions)
    • attributes: (IAttribute[])- array with attribute definitions
    • columnSeparator (string)- column separator (for CSV format, default: ",")
    • rowSeparator (string)- row separator (for CSV format. default: \n)
  • language (string) - language code (example: en, pl)
formatChatGptMessages
formatChatGptMessages({
  messages: ChatCompletionRequestMessage[],
  format: Format,
  options?: FormatOptions,
  language?: string
}): ChatCompletionRequestMessage[];
props
  • messages (ChatCompletionRequestMessage[]) - messages sent to chat-gpt api
  • format (Format) - format in which to return output from chat-gpt
  • options (FormatOptions)
    • attributes: (IAttribute[])- array with attribute definitions
    • columnSeparator (string)- column separator (for CSV format, default: ",")
    • rowSeparator (string)- row separator (for CSV format. default: \n)
  • language (string) - language code (example: en, pl)
formatChatGptRequest
formatChatGptRequest({
  request: CreateChatCompletionRequest,
  format: Format,
  options?: FormatOptions,
  language?: string
}): CreateChatCompletionRequest;
props
  • request (CreateChatCompletionRequest) - request config for chat-gpt api
  • format (Format) - format in which to return output from chat-gpt
  • options (FormatOptions)
    • attributes: (IAttribute[])- array with attribute definitions
    • columnSeparator (string)- column separator (for CSV format, default: ",")
    • rowSeparator (string)- row separator (for CSV format. default: \n)
  • language (string) - language code (example: en, pl)
Format
type Format = "array" | "csv" | "html" | "json" | "json-list" | "markdown" | "table" | "text" | "xml" | "yaml";
IAttribute
interface IAttribute {
    name: string;
    type: "string" | "number" | "boolean" | "date" | "integer" | "decimal" | Array<IAttribute>;
    minLength?: number;
    maxLength?: number;
    custom?: string;
}

For more information on ChatCompletionRequestMessage and CreateChatCompletionRequest please refer OpenAI documentation.

Building

To build format-gpt follow these steps:

  1. Clone this repository
  2. Install dependencies using npm install or yarn install command
  3. If using yarn with Visual Studio Code also run yarn dlx @yarnpkg/sdks vscode
  4. Run npm build or yarn build command

Tests

To run the test suite, first install the dependencies, then execute tests.

Using npm:

npm install
npm test

Using yarn:

yarn install
yarn test

License

This project is licensed under the MIT License.

FAQs

Package last updated on 25 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc