Skip to content

Commit

Permalink
fix: Fix log error handle and db bugs (#85)
Browse files Browse the repository at this point in the history
* fix db and test case

* fix log error handle

* chore: clean code

* update docs
  • Loading branch information
KenyonY authored Oct 26, 2023
1 parent 473d76e commit 2193bbe
Show file tree
Hide file tree
Showing 17 changed files with 882 additions and 816 deletions.
48 changes: 23 additions & 25 deletions .env
Original file line number Diff line number Diff line change
@@ -1,60 +1,58 @@
# 示例与解释见 .env.example
# Sample and explanation can be found in .env.example

# `LOG_CHAT`: 是否记录日志
#LOG_CHAT=true
# `LOG_CHAT`: Whether to log the chat
LOG_CHAT=true

CACHE_CHAT_COMPLETION=true
#CACHE_CHAT_COMPLETION=true

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

#BENCHMARK_MODE=true

# `OPENAI_BASE_URL`: 转发openai风格的任何服务地址,允许指定多个, 以逗号隔开。
# 如果指定超过一个,则任何OPENAI_ROUTE_PREFIX/EXTRA_ROUTE_PREFIX都不能为根路由/
#OPENAI_BASE_URL=https://api.openai-forward.com
# `OPENAI_BASE_URL`: Forward any service address in the style of OpenAI; multiple can be specified, separated by commas.
# If more than one is specified, neither OPENAI_ROUTE_PREFIX nor EXTRA_ROUTE_PREFIX can be the root route/
OPENAI_BASE_URL=https://api.openai.com

# `OPENAI_ROUTE_PREFIX`: 可指定所有openai风格(为记录日志)服务的转发路由前缀
OPENAI_ROUTE_PREFIX=
# `OPENAI_ROUTE_PREFIX`: Specify the forwarding route prefix for all services in OpenAI style (for logging purposes)
#OPENAI_ROUTE_PREFIX=

OPENAI_API_KEY=
FORWARD_KEY=
#OPENAI_API_KEY=
#FORWARD_KEY=

CHAT_COMPLETION_ROUTE=/v1/chat/completions
COMPLETION_ROUTE=/v1/completions

# `EXTRA_BASE_URL`: 可指定任意服务转发
EXTRA_BASE_URL=
# `EXTRA_ROUTE_PREFIX`: 与 EXTRA_BASE_URL 匹配的路由前缀
EXTRA_ROUTE_PREFIX=
# `EXTRA_BASE_URL`: Specify any service for forwarding
#EXTRA_BASE_URL=
# `EXTRA_ROUTE_PREFIX`: Route prefix matching EXTRA_BASE_URL
#EXTRA_ROUTE_PREFIX=

# `REQ_RATE_LIMIT`: i.e. 对指定路由的请求速率限制, 区分用户
# `REQ_RATE_LIMIT`: i.e., Request rate limit for specified routes, user specific
# 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
REQ_RATE_LIMIT={"/v1/chat/completions":"100/2minutes", "/v1/completions":"60/minute;600/hour"}

# rate limit后端: [memory, redis, memcached, ...] :ref: https://limits.readthedocs.io/en/stable/storage.html#
# Backend for rate limiting: [memory, redis, memcached, ...] :ref: https://limits.readthedocs.io/en/stable/storage.html#
#REQ_RATE_LIMIT_BACKEND=redis://localhost:6379

# `GLOBAL_RATE_LIMIT`: 限制所有`REQ_RATE_LIMIT`没有指定的路由. 不填默认无限制
# `GLOBAL_RATE_LIMIT`: Limits all routes not specified by `REQ_RATE_LIMIT`. If not set, there's no limit by default.
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 higher memory cost.
# `fixed-window`: most memory efficient strategy; `moving-window`:most effective for preventing bursts but has higher memory cost.
RATE_LIMIT_STRATEGY=moving-window

# 返回的token速率限制
# Rate limit for returned tokens
TOKEN_RATE_LIMIT={"/v1/chat/completions":"60/second","/v1/completions":"60/second"}


# TCP连接的超时时间(秒)
# TCP connection timeout duration (in seconds)
TIMEOUT=6

ITER_CHUNK_TYPE=one-by-one
#ITER_CHUNK_TYPE=efficiency

IP_BLACKLIST=
#IP_BLACKLIST=

# 设定时区
# Set timezone
TZ=Asia/Shanghai
35 changes: 24 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
# LOG_CHAT: 是否开启日志
# `LOG_CHAT`: 是否开启日志
# `LOG_CHAT`: Whether to log the chat
LOG_CHAT=true

PRINT_CHAT=true
#PRINT_CHAT=true

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

BENCHMARK_MODE=true

# OPENAI_BASE_URL: 转发openai风格的任何服务地址,允许指定多个, 以逗号隔开。
# `OPENAI_BASE_URL`: 转发openai风格的任何服务地址,允许指定多个, 以逗号隔开。
# 如果指定超过一个,则任何OPENAI_ROUTE_PREFIX/EXTRA_ROUTE_PREFIX都不能为根路由/
# `OPENAI_BASE_URL`: Forward any service address in the style of OpenAI; multiple can be specified, separated by commas.
# If more than one is specified, neither OPENAI_ROUTE_PREFIX nor EXTRA_ROUTE_PREFIX can be the root route/
OPENAI_BASE_URL='https://api.openai.com, http://localhost:8080'

# OPENAI_ROUTE_PREFIX: 可指定所有openai风格(为记录日志)服务的转发路由前缀
# `OPENAI_ROUTE_PREFIX`: 可指定所有openai风格(为记录日志)服务的转发路由前缀
# `OPENAI_ROUTE_PREFIX`: Specify the forwarding route prefix for all services in OpenAI style (for logging purposes)
OPENAI_ROUTE_PREFIX='/openai, /localai'

CHAT_COMPLETION_ROUTE=/openai/v1/chat/completions
COMPLETION_ROUTE=/v1/completions

# OPENAI_API_KEY:允许输入多个api key, 以逗号隔开, 形成轮询池
OPENAI_API_KEY='sk-xxx1, sk-xxx2, sk-xxx3'
# `OPENAI_API_KEY`:配置OpenAI 接口风格的API密钥,支持使用多个密钥,通过逗号分隔
# `OPENAI_API_KEY`: Configure API key in OpenAI style, supports using multiple keys separated by commas
OPENAI_API_KEY='sk-***, sk-***, sk-***'

# FORWARD_KEY: 当前面的OPENAI_API_KEY被设置,就可以设置这里的FORWARD_KEY,客户端调用时可以使用FORWARD_KEY作为api key
FORWARD_KEY=fk-xxx1
# `FORWARD_KEY`: 当前面的OPENAI_API_KEY被设置,就可以设置这里的FORWARD_KEY,客户端调用时可以使用FORWARD_KEY作为api key
# `FORWARD_KEY`: Set a custom key for proxying, multiple keys can be separated by commas.
FORWARD_KEY='fk-***, ***, 123'

# EXTRA_BASE_URL: 可指定任意服务转发
# `EXTRA_BASE_URL`: Specify any service for forwarding
EXTRA_BASE_URL='http://localhost:8882, http://localhost:8881'

# EXTRA_ROUTE_PREFIX: 与 EXTRA_BASE_URL 匹配的路由前缀
# `EXTRA_ROUTE_PREFIX`: Route prefix matching EXTRA_BASE_URL
EXTRA_ROUTE_PREFIX='/tts, /translate'

# `REQ_RATE_LIMIT`: 指定路由的请求速率限制(区分用户)
# `REQ_RATE_LIMIT`: i.e., Request rate limit for specified routes, user specific
# 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
REQ_RATE_LIMIT='{
Expand All @@ -40,6 +49,8 @@ REQ_RATE_LIMIT='{
}'

# rate limit后端: [memory, redis, Memcached, ...] :ref: https://limits.readthedocs.io/en/stable/storage.html#
# Backend for rate limiting: [memory, redis, memcached, ...] :ref: https://limits.readthedocs.io/en/stable/storage.html#
# Assuming your Redis service is at localhost:6379
REQ_RATE_LIMIT_BACKEND="redis://localhost:6379"

# `GLOBAL_RATE_LIMIT`: 限制所有`REQ_RATE_LIMIT`没有指定的路由. 不填默认无限制
Expand All @@ -53,12 +64,14 @@ RATE_LIMIT_STRATEGY=fixed-window
PROXY=http://localhost:7890

# `TOKEN_RATE_LIMIT` 对每一份流式返回的token速率限制 (注:这里的token并不严格等于gpt中定义的token,而是SSE的chunk)
# Rate limit for returned tokens
TOKEN_RATE_LIMIT={"/v1/chat/completions":"20/second", "/benchmark/v1/chat/completions":"500/second"}


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

ITER_CHUNK_TYPE=efficiency
#ITER_CHUNK_TYPE=one-by-one

# 设定时区
# Set timezone
TZ=Asia/Shanghai
1 change: 1 addition & 0 deletions Examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config.yaml
lite_example
Loading

0 comments on commit 2193bbe

Please sign in to comment.