Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/acheong08/ChatGPT-API-server

API server for ChatGPT
https://github.com/acheong08/ChatGPT-API-server

Last synced: 5 days ago
JSON representation

API server for ChatGPT

Awesome Lists containing this project

README

        

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

# ChatGPT API Server
[![Release Go Binaries](https://github.com/acheong08/ChatGPT-API-server/actions/workflows/release.yml/badge.svg)](https://github.com/acheong08/ChatGPT-API-server/actions/workflows/release.yml)
# 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 `

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](https://github.com/acheong08/ChatGPT-API-agent). More versions in the works.

There is also a [Python based client](https://github.com/ahmetkca/chatgpt-unofficial-api-docker/tree/ChatGPT-API-agent) by @ahmetkca (WIP)

# Usage

## Quickstart

(After connecting agents)

```bash
$ curl "http://localhost:8080/api/ask" -X POST --header 'Authorization: ' -d '{"content": "Hello world", "conversation_id": "", "parent_id": ""}'
```
Note: if you want to use `conversation_id`, you also need to use `parent_id`!

## Routes

```go
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: `

_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:

```json
{
"content": "Hello world",
"conversation_id": "",
"parent_id": ""
}
```

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:

```json
{
"id": "",
"response_id": "",
"conversation_id": "",
"content": "",
"error": ""
}
```

#### /api/connections (GET)

Headers: None

Data: None

Response:

```json
{
"connections": [
{
"Ws": {},
"Id": "",
"Heartbeat": "

#### /admin/users/add (POST)

Headers: None

Data:

```json
{
"admin_key": ""
}
```

Response:

```json
{
"user_id": "",
"token": ""
}
```

#### /admin/users/delete (POST)

Headers: None

Data:

```json
{
"admin_key": "",
"user_id": ""
}
```

Response:

```json
{ "message": "User deleted" }
```

#### /admin/users (GET)

Parameters: `?admin_key=`

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

Response:

```json
{
"users": [
{
"user_id": "",
"token": ""
},
{
"user_id": "",
"token": ""
},
{
"user_id": "",
"token": ""
},
{
"user_id": "",
"token": ""
},
...
]
}
```

# Docker

open `docker-compose.yml` and add your own custom api-key in `` section

```yaml
version: "3"

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

then run:

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