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

openai-toolkit

v1.2.0

Published

A toolkit to query openAI language models.

Downloads

11

Readme

OpenAI Toolkit

The OpenAI Toolkit is a Node.js module that provides a convenient interface for interacting with OpenAI's GPT models through the OpenAI API. It allows you to generate text based on prompts and provides additional features such as estimating token count and cost.

Prerequisites

Before using the OpenAI Toolkit, make sure you have the following installed:

  • Node.js
  • NPM (Node Package Manager)

Installation

  1. Install the OpenAI Toolkit module by running the following command in your project directory:

    npm install openai-toolkit
  2. Require the module in your JavaScript file:

    const { call } = require('openai-toolkit');

Usage

To use the OpenAI Toolkit, follow these steps:

  1. Get your OpenAI API key from the OpenAI website. You will need this key to make API requests.

  2. Create a new JavaScript file (e.g., app.js) and require the OpenAI Toolkit module:

    const { call } = require('openai-toolkit');
  3. Use the call function to generate text:

    call(input, temperature, maxTokens, modelType, PARAMETERS, apiKey, onData, onEnd);
    • input (string): The prompt for generating text.
    • temperature (number): Controls the randomness of the generated text. A higher value (e.g., 0.8) produces more random outputs, while a lower value (e.g., 0.2) produces more deterministic outputs.
    • maxTokens (number): Limits the length of the generated text. You can set the maximum number of tokens the model should generate.
    • modelType (string): Specifies the GPT model to use. For example, "gpt-3.5-turbo" is the most advanced model as of the last update.
      • Valid options are: 'gpt-4','gpt-4-0314', 'gpt-4-32k', 'gpt-4-32k-0314', 'gpt-3.5-turbo', 'gpt-3.5-turbo-0301'
      • note you can only use gpt-4-* models if you have been given access by the openAI team, you do not have them default.
    • PARAMETERS (string): Additional parameters for customizing the behavior of the function. Supported options include:
      • "a": Enable analytics to estimate token count and cost.
      • "e": Append an end indicator to the generated output.
      • "s": Silent mode, disables additional output.
    • apiKey (string): Your OpenAI API key.
    • onData (function): Callback function to handle the generated output. Receives the generated text as a parameter.
    • onEnd (function): Callback function called when the generation process ends.
  4. Run your JavaScript file using Node.js:

    node app.js
  5. The generated text will be displayed according to your specified parameters.

Examples

Here are some examples of using the OpenAI Toolkit:

  1. Basic Usage:

    const { call } = require('openai-toolkit');
    
    const input = 'Hello, GPT!';
    const temperature = 0.6;
    const maxTokens = 50;
    const modelType = 'gpt-3.5-turbo';
    const PARAMETERS = '';
    const apiKey = 'your_api_key_here';
    
    function onData(output) {
      console.log(output);
    }
    
    function onEnd() {
      console.log('Generation completed.');
    }
    
    call(input, temperature, maxTokens, modelType, PARAMETERS, apiKey, onData, onEnd);
  2. Analytics and Token Count:

    const { call } = require('openai-toolkit');
    
    const input = 'Hello, GPT!';
    const temperature = 0.6;
    const maxTokens = 50;
    const modelType = 'gpt-3.5-turbo';
    const PARAMETERS = 'a';
    const apiKey = 'your_api_key_here';
    
    function onData(output) {
      console.log(output);
    }
    
    function onEnd() {
      console.log('Generation completed.');
    }
    
    call(input, temperature, maxTokens, modelType, PARAMETERS, apiKey, onData, onEnd);

License

Feel free to use this project as you please!