nodegptwrapper
v1.1.23
Published
An unofficial gpt wrapper for nodejs
Downloads
323
Readme
GPT-API Wrapper
This package provides a convenient wrapper for interacting with OpenAI's GPT and DALL-E models, allowing for both chat and image generation functionalities.
Table of Contents
Installation
Install the package using npm:
npm install nodejsgptwrapper
Usage
Here's a quick example to demonstrate how to use this package:
Chat with GPT
const {
askGptWithHistory,
gptChatMessage,
gptMessageContent,
models,
} = require("nodejsgptwrapper");
const apiKey = "your-openai-api-key";
const history = [
new gptChatMessage("user", new gptMessageContent("Hello, GPT!")),
];
askGptWithHistory(models.CHAT.GPT4, history, apiKey)
.then((response) => {
console.log("GPT Response:", response);
})
.catch((error) => {
console.error("Error:", error);
});
Generate an Image
const { generateImage, gptImageRequest, models } = require("nodejsgptwrapper");
const apiKey = "your-openai-api-key";
const imageRequest = new gptImageRequest("A futuristic cityscape", 1, 512);
generateImage(models.IMAGE_GENERATION.DALLE3, imageRequest, apiKey)
.then((imageData) => {
console.log("Generated Image Data:", imageData);
})
.catch((error) => {
console.error("Error:", error);
});
API Reference
Functions
askGptWithHistory(model, history, apiKey) : Promise
- Sends a chat message to the GPT model with a history context and returns a promise resolving to the model's response.
- model: the model to use (e.g.,
models.CHAT.GPT3
). - history: an array of
gptChatMessage
objects. - apiKey: your OpenAI API key.
generateImage(model, imageRequest, apiKey) : Promise
- Sends an image generation request to DALL-E.
- model: the model to use (e.g.,
models.IMAGE_GENERATION.DALLE3
). - imageRequest: an instance of
gptImageRequest
. - apiKey: your OpenAI API key.
Classes
gptChatMessage
- Represents a chat message with a role and content.
gptMessageContent
- Represents the content of a chat message.
gptImageRequest
- Represents an image generation request.
gptImageContent
- Represents image content with text and a URL.
Models
CHAT
GPT3
,GPT4
,GPT4TURBO
,GPT4O
,GPT4OMINI
,O1
,O1MINI
IMAGE_GENERATION
DALLE3
IMAGE_RECOGNITION
GPT4VISION
Roles
- SYSTEM
- GPT (Assistant)
- USER