Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chatgpt-optimized-official

Package Overview
Dependencies
Maintainers
0
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chatgpt-optimized-official

ChatGPT Client using official OpenAI API

  • 1.2.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
decreased by-52.78%
Maintainers
0
Weekly downloads
 
Created
Source

chatgpt-optimized-official - Create ChatGPT effortlessly using OpenAI's official API

chatgpt-optimized-official is a streamlined Node.js module built to facilitate the creation and interaction of ChatGPT bots using the official OpenAI API.

📦 Installation

Install the package using npm:


npm install chatgpt-optimized-official


🚀 Quick Start

Using ChatGPT with OpenAI's Chat Completion API


import { ChatGPT } from "chatgpt-optimized-official";

const bot = new ChatGPT("<OPENAI_API_KEY>");
const response = await bot.ask("Hello?");
console.log(response);

Using OpenAI's Official Completion API


import { OpenAI } from "chatgpt-optimized-official";

const bot = new OpenAI("<OPENAI_API_KEY>");
const response = await bot.ask("Hello?");
console.log(response);

🛠 Advanced Usage

Detailed Configuration with ChatGPT

Here, we provide various OpenAI parameters and set up different conversation scenarios:


import { ChatGPT } from "chatgpt-optimized-official";

const options = {
    temperature: 0.7,
    max_tokens: 100,
    top_p: 0.9,
    frequency_penalty: 0,
    presence_penalty: 0,
    instructions: `You are ChatGPT, a large language model trained by OpenAI.`,
    model: "gpt-3.5-turbo", 
};

const bot = new ChatGPT("<OPENAI_API_KEY>", options); 

// Basic Interaction
const response = await bot.ask("Hello?");
console.log(response);

// Conversation scenarios with unique IDs
const response1 = await bot.ask("Hello?", "conversation1");
console.log(response1);

const response2 = await bot.ask("Hello?", "conversation2");
console.log(response2);

Advanced Features: Functions & Variations

Incorporate functions and use advanced features such as specifying message roles and custom user names:


import { ChatGPT } from "chatgpt-optimized-official";

const options = {
    ...,
    model: "gpt-3.5-turbo-0613",
    functions: [{
        "name": "saveDataUser",
        "description": "Save user data",
        "parameters": {
            "type": "object",
            "properties": {
                "name": {"type": "string", "description": "User's name"},
                "email": {"type": "string", "description": "User's email"},
                "phone": {"type": "string", "description": "User's phone number"}
            },
            "required": ["name", "email", "phone"],
        }
    }],
    function_call: "auto"
};

const bot = new ChatGPT("<OPENAI_API_KEY>", options); 

const response = await bot.askV1("Hello?");
console.log(response);

const type = 1; // 1: User, 2: Assistant. Default is 1.
const userName = "User"; // Optional: Custom username.
const response1 = await bot.askV1("Hello?", "conversation1", type, userName);
console.log(response1);

Using OpenAI's Completion API

Demonstrate the use of a different model with OpenAI's API:


import { OpenAI } from "chatgpt-optimized-official";

const options = {
    ...,
    model: "text-davinci-003", 
};

const bot = new OpenAI("<OPENAI_API_KEY>", options); 

const response = await bot.ask("Hello?");
console.log(response);

const response1 = await bot.ask("Hello?", "conversation1");
console.log(response1);

const response2 = await bot.ask("Hello?", "conversation2");
console.log(response2);


This version organizes the information more cleanly, uses icons for better visibility, adds subtitles for clarity, and improves the general flow and wording.

Keywords

FAQs

Package last updated on 10 Jul 2024

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