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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sdk-open-ai

v2.0.4

Published

SDK for ChatGPT language model based on OpenAI API

Readme

OpenAI ChatGPT based on model gpt-3.5-turbo

OpenAI ChatGPT SDK, built with Node & TypeScript.

Table of Contents

General Information

sdk-open-ai allows developers to incorporate Open AI features into their applications, such as getting list models, retrieve a model, create a chat completion, create edit, create embeddings, create moderation, create image, create image edit, create image variation. The SDK was created to simplify and streamline the process of integrating these functionalities into applications.

Technologies Used

  • Node.js - version 18.14.0
  • TypeScript - version 5.0.3

Features

  • Create a chat completion in a similar way to the ChatGPT application.
  • Access to various methods to retrieve detailed information.
  • Simple and intuitive interface for easy integration.

Installation

To install the SDK, simply run the following command on your project:

npm install sdk-open-ai
//OR
yarn add sdk-open-ai

Usage

To use the SDK, simply import it into your app.ts file in your project and create a new instance of the OpenAI class:

import OpenAI from "sdk-open-ai";

The OpenAI constructor accepts a configuration object with the following properties:

  • The apiKey property is required. To utilize the SDK, you are required to obtain an access token from https://rapidapi.com/openai-api-openai-api-default/api/openai80/.
  • The baseUrl is optional and has a default value of https://openai80.p.rapidapi.com/. It is only necessary to include the baseUrl property if a fresh version of the API is published.
const client = new OpenAI({
  apiKey: "token", // An access token is required.
});

Methods

The SDK provides a number of methods for accessing various endpoints of the API. All methods return a Promise that resolves with the API response.

The getModels() method retrieves all the language models available in the API.

client
  .getModels()
  .then((res) => {
    console.log("List of models:", res);
  })
  .catch((error) => {
    console.log("Error", error.message);
  });

The getModelByName(name) method retrieves a single language model instance using its name. The name should be provided as a string, the following are some language model name for the OpenAI models:

const name = "gpt-3.5-turbo";
//or
//const name = "babbage";
//const name = "davinci";

client
  .getModelByName(name)
  .then((model) => {
    console.log("Retrieves a single model name", model);
  })
  .catch((error) => {
    console.log("Error", error.message);
  });

The createChatCompletion(newChat) method creates a completion for the chat message. The method takes an object with the model name as a string and messages array of object that specifies the role and content for the chat to be retrieved.

const newChat = {
  model: "gpt-3.5-turbo",
  messages: [
    {
      role: "user",
      content: "tell me about a good place for pizza?",
    },
  ],
};

client
  .createChatCompletion(newChat)
  .then((res: any) => {
    console.log(res.choices.map((chat) => chat.message));
  })
  .catch((error) => {
    console.log("Error", error.message);
  });

How to test the SDK

  • Open your project folder in a code editor or terminal.
  • Run the following command in the terminal to initialize a new TypeScript project:
npm init -y
  • Run the following command to install TypeScript as a development dependency:
npm install typescript -D
//OR
yarn add typescript -D
  • Run the following command to create a tsconfig.json file:
npx tsc --init
  • This command generates a default tsconfig.json file in the root directory of your project.

  • Copy and paste the code snippet below into the tsconfig.json file to replace its default content. This configuration sets options for the TypeScript compiler such as module, declaration, target, and outDir. The include property specifies the directories or files to be compiled, while the exclude property specifies the directories or files to be excluded from compilation.

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "target": "ES2017",
    "sourceMap": false,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "experimentalDecorators": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "test", "lib", "**/*spec.ts"]
}
  • Now, compile the TypeScript files to JavaScript using the TypeScript compiler (tsc) by running the following command:
npx tsc
  • This will generate compiled JavaScript files in a new dist directory, based on the configuration defined in the tsconfig.json file.

  • You can now test the SDK using the compiled JavaScript files in the dist director by running the following command:

node dist/app.js

Acknowledgements

  • This project was inspired by the ChatGPT language model.
  • Many thanks to the creators of the following resources that were used in the development of this project:
  • Rapid API: https://rapidapi.com/openai-api-openai-api-default/api/openai80/
  • OpenAI API: https://openai80.p.rapidapi.com/
  • microbundle: https://www.npmjs.com/package/microbundle

MIT License

Copyright (c) [2023] [Elhassan Abdelhafez]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software.

Contact

  • Created by https://github.com/hassandiv - feel free to contact me!