Tag
ChatGPT
Type
Code
Created
Mar 30, 2023 03:36 AM
notion image

Updates

Details Details

ChatGPT API

notion image
notion image
notion image
notion image

Table of Contents

Features

  • Includes an API server (with Docker support) you can run to use ChatGPT in non-Node.js applications.
  • Includes a CLI interface where you can chat with ChatGPT.
  • Includes clients that you can use in your own Node.js applications.
  • ChatGPTClient: support for the official ChatGPT underlying model, gpt-3.5-turbo, via OpenAI's API.
    • Replicates chat threads from the official ChatGPT website (with conversation IDs and message IDs), with persistent conversations using Keyv.
      • Conversations are stored in memory by default, but you can optionally install a storage adapter to persist conversations to a database.
      • The keyv-file adapter is also included in this package, and can be used to store conversations in a JSON file if you're using the API server or CLI (see settings.example.js).
    • Supports configurable prompt prefixes, and custom names for the user and ChatGPT.
      • In essence, this allows you to make a chatbot with any personality you want.
      • This is currently only configurable on a global level, but I plan to add support for per-conversation customization.
    • Retains support for models like text-davinci-003
  • BingAIClient: support for Bing's version of ChatGPT, powered by GPT-4.
    • Includes a built-in jailbreak you can activate which enables unlimited chat messages per conversation, unlimited messages per day, and brings Sydney back.
      • notion image
  • ChatGPTBrowserClient: support for the official ChatGPT website, using a reverse proxy server for a Cloudflare bypass.
    • There may be a high chance of your account being banned if you continue to automate chat.openai.com. Continue doing so at your own risk.

Getting Started

Prerequisites

  • Node.js >= 16.0.0
  • npm
  • Docker (optional, for API server)

Usage

Module

Details Details Details

API Server

Setup

You can install the package using
then run it using chatgpt-api. This takes an optional --settings=<path_to_settings.js> parameter, or looks for settings.js in the current directory if not set, with the following contents:
Details
Alternatively, you can install and run the package directly.
  1. Clone this repository: git clone https://github.com/waylaidwanderer/node-chatgpt-api
  1. Install dependencies with npm install (if not using Docker)
  1. Rename settings.example.js to settings.js in the root directory and change the settings where required.
  1. Start the server:
      • using npm start or npm run server (if not using Docker)
      • using docker-compose up (requires Docker)

Endpoints

Details

Usage

Details Details

Notes

  • Method 1 is simple, but Time to First Byte (TTFB) is long.
  • Method 2 uses a non-standard implementation of server-sent event API; you should import fetch-event-source first and use POST method.

CLI

Setup

Follow the same setup instructions for the API server, creating settings.js.

Usage

If installed globally:
If installed locally:
ChatGPT's responses are automatically copied to your clipboard, so you can paste them into other applications.

Using a Reverse Proxy

As shown in the examples above, you can set reverseProxyUrl in ChatGPTClient's options to use a reverse proxy server instead of the official ChatGPT API. For now, this is the only way to use the ChatGPT underlying models. This method has been patched and the instructions below are no longer relevant, but you may still want to use a reverse proxy for other reasons. Currently, reverse proxy servers are still used for performing a Cloudflare bypass for ChatGPTBrowserClient.
Details

Projects

notion image
A list of awesome projects using @waylaidwanderer/chatgpt-api:
  • PandoraAI: my web chat client powered by node-chatgpt-api, allowing users to easily chat with multiple AI systems while also offering support for custom presets. With its seamless and convenient design, PandoraAI provides an engaging conversational AI experience.
  • ChatGPT Clone: a clone of ChatGPT, uses official model, reverse-engineered UI, with AI model switching, message search, and prompt templates.
  • ChatGPT WebApp: a fullstack chat webapp with mobile compatble UI interface, and node-chatgpt-api works as backend. Anyone can deploy your own chat service.
  • halbot: Just another ChatGPT/Bing Chat Telegram bot, which is simple design, easy to use, extendable and fun.
  • ChatGPTBox: Integrating ChatGPT into your browser deeply, everything you need is here
Add yours to the list by editing this README and creating a pull request!

Web Client

A web client for this project is also available at waylaidwanderer/PandoraAI.

Caveats

Regarding ChatGPTClient

Since gpt-3.5-turbo is ChatGPT's underlying model, I had to do my best to replicate the way the official ChatGPT website uses it. This means my implementation or the underlying model may not behave exactly the same in some ways:
  • Conversations are not tied to any user IDs, so if that's important to you, you should implement your own user ID system.
  • ChatGPT's model parameters (temperature, frequency penalty, etc.) are unknown, so I set some defaults that I thought would be reasonable.
  • Conversations are limited to roughly the last 3000 tokens, so earlier messages may be forgotten during longer conversations.
    • This works in a similar way to ChatGPT, except I'm pretty sure they have some additional way of retrieving context from earlier messages when needed (which can probably be achieved with embeddings, but I consider that out-of-scope for now).

Contributing

If you'd like to contribute to this project, please create a pull request with a detailed description of your changes.

License

This project is licensed under the MIT License.
  • Twikoo
公告
🎉欢迎光临🎉
-- 感谢您的支持 ---