Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
KenyonY committed Aug 16, 2023
1 parent 54de3b3 commit e828341
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
10 changes: 5 additions & 5 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LOG_CHAT=false

# `OPENAI_BASE_URL`: 转发openai风格的任何服务地址,允许指定多个, 以逗号隔开。
# 如果指定超过一个,则任何OPENAI_ROUTE_PREFIX/EXTRA_ROUTE_PREFIX都不能为根路由/
OPENAI_BASE_URL=https://api.openai-forward.com
OPENAI_BASE_URL=https://api.openai.com

# `OPENAI_ROUTE_PREFIX`: 可指定所有openai风格(为记录日志)服务的转发路由前缀
OPENAI_ROUTE_PREFIX=
Expand All @@ -18,12 +18,12 @@ EXTRA_BASE_URL=
# `EXTRA_ROUTE_PREFIX`: 与 EXTRA_BASE_URL 匹配的路由前缀
EXTRA_ROUTE_PREFIX=

# RATE `LIMIT`: 指定路由的请求速率限制
# `RATE_LIMIT`: i.e. RPM 对指定路由的请求速率限制
# format: {route: ratelimit-string}
# ratelimit-string format [count] [per|/] [n (optional)] [second|minute|hour|day|month|year] :ref:`ratelimit-string`: https://limits.readthedocs.io/en/stable/quickstart.html#rate-limit-string-notation
RATE_LIMIT='{
"/healthz": "1000/2minutes",
"/v1/chat/completions": "5/second",
"/v1/chat/completions": "300/minute"
}'

#`RATE_LIMIT_STRATEGY` Options: (fixed-window, fixed-window-elastic-expiry, moving-window) ref: https://limits.readthedocs.io/en/latest/strategies.html
Expand All @@ -33,8 +33,8 @@ RATE_LIMIT_STRATEGY=moving-window
# `GLOBAL_RATE_LIMIT`: 所有`RATE_LIMIT`没有指定的路由. 不填默认无限制
GLOBAL_RATE_LIMIT=

# same as TPM
TOKEN_RATE_LIMIT=60/second
# TPM: 返回的token速率限制
TOKEN_RATE_LIMIT=50/second

# 设定时区
TZ=Asia/Shanghai
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RATE_LIMIT_STRATEGY=fixed-window
# `PROXY` http代理
PROXY=http://localhost:7890

# `TOKEN_RATE_LIMIT` 对每一份流式请求的token速率限制 (注:这里的token并不是gpt中定义的token,而是SSE的chunk)
# `TOKEN_RATE_LIMIT` 对每一份流式返回的token速率限制 (注:这里的token并不严格等于gpt中定义的token,而是SSE的chunk)
TOKEN_RATE_LIMIT=16/second

# 设定时区
Expand Down
1 change: 0 additions & 1 deletion openai_forward/forwarding/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ async def aiter_bytes(
current_time = time.perf_counter()
delta = current_time - start_time
sleep_time = TOKEN_INTERVAL - delta
print(f"{delta=} {sleep_time=}")
if sleep_time > 0:
time.sleep(sleep_time)
start_time = time.perf_counter()
Expand Down
3 changes: 1 addition & 2 deletions openai_forward/forwarding/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import limits
from fastapi import Request

from ..config import setting_log
from ..config import print_startup_info, setting_log, show_rate_limit_info
from ..helper import env2dict, env2list, format_route_prefix, get_client_ip

ENV_VAR_SEP = ","
Expand Down Expand Up @@ -60,7 +60,6 @@ def dynamic_rate_limit(key: str):
else:
TOKEN_INTERVAL = 0

from ..config import print_startup_info, show_rate_limit_info

for base_url, route_prefix in zip(OPENAI_BASE_URL, OPENAI_ROUTE_PREFIX):
print_startup_info(base_url, route_prefix, OPENAI_API_KEY, FWD_KEY, LOG_CHAT)
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ markers =
timeout: marks test timeout duration
repeat: marks that test run n times
addopts = --doctest-modules --doctest-glob=README.md --doctest-glob=*.py --ignore=setup.py
norecursedirs = Examples ssl
norecursedirs = Examples ssl scripts

0 comments on commit e828341

Please sign in to comment.