Coder Social home page Coder Social logo

chatgpt-api-server's Introduction

Official API released by OpenAI. Please use that instead. The model name is text-chat-davinci-002-20230126

ChatGPT API Server

Release Go Binaries

Quickstart

Setup

  1. Install Go
  2. go install github.com/acheong08/ChatGPT-API-server@latest

If the latest commit fails, try using one of the release binaries

Build

  1. git clone https://github.com/acheong08/ChatGPT-API-server/
  2. cd ChatGPT-API-server
  3. go install .

Usage

ChatGPT-API-server <port> <API_KEY>

The admin key can be anything you want. It's just for authenticating yourself.

Connect agents

Take note of your IP address or domain name. This could be localhost or a remote IP address. The default port is 8080

Check out our firefox agent. More versions in the works.

There is also a Python based client by @ahmetkca (WIP)

Usage

Quickstart

(After connecting agents)

 $ curl "http://localhost:8080/api/ask" -X POST --header 'Authorization: <API_KEY>' -d '{"content": "Hello world", "conversation_id": "<optional>", "parent_id": "<optional>"}'

Note: if you want to use conversation_id, you also need to use parent_id!

Routes

	router.GET("/client/register", handlers.Client_register) // Used by agent
	router.POST("/api/ask", handlers.API_ask) // For making ChatGPT requests
	router.GET("/api/connections", handlers.API_getConnections) // For debugging
	router.POST("/admin/users/add", handlers.Admin_userAdd) // Adds an API token
	router.POST("/admin/users/delete", handlers.Admin_userDel) // Invalidates a token (based on user_id)
	router.GET("/admin/users", handlers.Admin_usersGet) // Get all users

Parameters for each route

/client/register (GET)

N/A. Used for websocket

/api/ask (POST)

Headers: Authorization: <USER_TOKEN>

The user token can be set by the admin via /admin/users/add. You can also use the api key as the token. Both work by default

Data:

{
  "content": "Hello world",
  "conversation_id": "<optional>",
  "parent_id": "<optional>"
}

Do not enter conversation or parent id if not available. If you want to use either of these, you need to specify both! i.e. request.parent_id=response.response_id and request.conversation_id=response.conversation_id

Response:

{
  "id": "",
  "response_id": "<UUID>",
  "conversation_id": "<UUID>",
  "content": "<string>",
  "error": ""
}

/api/connections (GET)

Headers: None

Data: None

Response:

{
  "connections": [
    {
      "Ws": {},
      "Id": "<UUID>",
      "Heartbeat": "<Time string>",
      "LastMessageTime": "<Time string>"
    }
  ]
}

/admin/users/add (POST)

Headers: None

Data:

{
  "admin_key": "<string>"
}

Response:

{
  "user_id": "<UUID>",
  "token": "<UUID>"
}

/admin/users/delete (POST)

Headers: None

Data:

{
  "admin_key": "<string>",
  "user_id": "<UUID>"
}

Response:

{ "message": "User deleted" }

/admin/users (GET)

Parameters: ?admin_key=<string>

Example usage: curl "http://localhost:8080/admin/users?admin_key=some_random_key"

Response:

{
  "users": [
    {
      "user_id": "<UUID>",
      "token": "<UUID>"
    },
    {
      "user_id": "<UUID>",
      "token": "<UUID>"
    },
    {
      "user_id": "<UUID>",
      "token": "<UUID>"
    },
    {
      "user_id": "<UUID>",
      "token": "<UUID>"
    },
    ...
  ]
}

Docker

open docker-compose.yml and add your own custom api-key in <API_KEY> section

version: "3"

services:
  chatgpt-api-server:
    build: .
    ports:
      - "8080:8080"
    command: ["ChatGPT-API-server", "8080", "<API_KEY>", "-listen", "0.0.0.0"]

then run:

docker-compose up or docker-compose up -d (if you want a persistent instance)

chatgpt-api-server's People

Contributors

sadmap avatar axsddlr avatar mrloldev avatar 0xraduan avatar iakat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.