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
- Installation
- Usage
- API Reference
- Building
- Tests
- 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-gptformat (Format)
- format in which to return output from chat-gptoptions (FormatOptions)
attributes: (IAttribute[])
- array with attribute definitionscolumnSeparator (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 apiformat (Format)
- format in which to return output from chat-gptoptions (FormatOptions)
attributes: (IAttribute[])
- array with attribute definitionscolumnSeparator (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 apiformat (Format)
- format in which to return output from chat-gptoptions (FormatOptions)
attributes: (IAttribute[])
- array with attribute definitionscolumnSeparator (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:
- Clone this repository
- Install dependencies using
npm install
or yarn install
command - If using
yarn
with Visual Studio Code also run yarn dlx @yarnpkg/sdks vscode
- 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.