Skip to content

Commit

Permalink
forward chatgpt example (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
KenyonY authored Nov 16, 2023
1 parent f112ccd commit 0e067b8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 31 deletions.
43 changes: 43 additions & 0 deletions .env.chatgpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
LOG_CHAT=true

CACHE_CHAT_COMPLETION=true

# `CACHE_BACKEND`: Options (MEMORY, LMDB, LevelDB)
CACHE_BACKEND=LMDB

#LOG_CACHE_DB_INFO=true

OPENAI_BASE_URL='https://api.openai.com/v1'
OPENAI_ROUTE_PREFIX='/v1'

CHAT_COMPLETION_ROUTE=/chat/completions
COMPLETION_ROUTE=/completions

#OPENAI_API_KEY=
#FORWARD_KEY=


EXTRA_BASE_URL='http://chatgpt:7999'
EXTRA_ROUTE_PREFIX='/'

REQ_RATE_LIMIT={"/v1/chat/completions":"100/2minutes", "/v1/completions":"60/minute;600/hour"}

#GLOBAL_RATE_LIMIT=100/minute

#`RATE_LIMIT_STRATEGY` Options: (fixed-window, fixed-window-elastic-expiry, moving-window) :ref: https://limits.readthedocs.io/en/latest/strategies.html
# `fixed-window`: most memory efficient strategy; `moving-window`:most effective for preventing bursts but has higher memory cost.
RATE_LIMIT_STRATEGY=moving-window

# Rate limit for returned tokens
TOKEN_RATE_LIMIT={"/v1/chat/completions":"60/second","/v1/completions":"60/second"}

# TCP connection timeout duration (in seconds)
TIMEOUT=6

ITER_CHUNK_TYPE=one-by-one
#ITER_CHUNK_TYPE=efficiency

#IP_BLACKLIST=

# Set timezone
TZ=Asia/Shanghai
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ LOG_CHAT=true
#PRINT_CHAT=true

CACHE_CHAT_COMPLETION=true
# `CACHE_BACKEND`: Options (MEMORY, LMDB, ROCKSDB, LevelDB)
CACHE_BACKEND=MEMORY
# `CACHE_BACKEND`: Options (MEMORY, LMDB, LevelDB)
CACHE_BACKEND=LMDB

BENCHMARK_MODE=true

Expand Down
31 changes: 5 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

</div>

**OpenAI-Forward** 是为大型语言模型设计的高效转发服务。其核心功能包括
**OpenAI-Forward** 是为大型语言模型实现的高效转发服务。其核心功能包括
用户请求速率控制、Token速率限制、智能预测缓存、日志管理和API密钥管理等,旨在提供高效、便捷的模型转发服务。
无论是代理本地语言模型还是云端语言模型,如 [LocalAI](https://github.com/go-skynet/LocalAI)[OpenAI](https://api.openai.com),都可以由 OpenAI Forward 轻松实现。
凭借 [uvicorn](https://github.com/encode/uvicorn), [aiohttp](https://github.com/aio-libs/aiohttp), 和 [asyncio](https://docs.python.org/3/library/asyncio.html)
Expand Down Expand Up @@ -155,8 +155,6 @@ docker run -d \
yidadaa/chatgpt-next-web
```

#### 在代码中接入

**Python**

```diff
Expand All @@ -165,29 +163,6 @@ docker run -d \
openai.api_key = "sk-******"
```

**JS/TS**

```diff
import { Configuration } from "openai";

const configuration = new Configuration({
+ basePath: "https://api.openai-forward.com/v1",
apiKey: "sk-******",
});
```

**gpt-3.5-turbo**

```bash
curl https://api.openai-forward.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-******" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}'
```

**Image Generation (DALL-E)**

```bash
Expand Down Expand Up @@ -224,6 +199,10 @@ curl --location 'https://api.openai-forward.com/v1/images/generations' \

(更多)

### 代理ChatGPT
参考根路径下 `docker-compose.yaml``.env.chatgpt`


<a>
<img src="https://raw.githubusercontent.com/KenyonY/openai-forward/main/.github/images/separators/aqua.png" height=8px width="100%">
</a>
Expand Down
7 changes: 4 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ services:
- --workers=1
restart: unless-stopped
depends_on:
- ninja
- chatgpt

ninja:
chatgpt:
# use project: https://github.com/gngpp/ninja
image: ghcr.io/gngpp/ninja:latest
container_name: ninja
container_name: chatgpt
restart: unless-stopped
environment:
- TZ=Asia/Shanghai
Expand Down

0 comments on commit 0e067b8

Please sign in to comment.