Merge pull request #332 from RockChinQ/reverse-proxy

[Feat] 支持反向代理
This commit is contained in:
Rock Chin 2023-03-26 22:51:06 +08:00 committed by GitHub
commit 44f4820cee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -33,11 +33,26 @@ mirai_http_api_config = {
# }, # },
# "http_proxy": "http://127.0.0.1:12345" # "http_proxy": "http://127.0.0.1:12345"
# } # }
#
# 现已支持反向代理可以添加reverse_proxy字段以使用反向代理
# 使用反向代理可以在国内使用OpenAI的API反向代理的配置请参考
# https://github.com/Ice-Hazymoon/openai-scf-proxy
#
# 反向代理填写示例:
# openai_config = {
# "api_key": {
# "default": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
# "key1": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
# "key2": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
# },
# "reverse_proxy": "http://example.com:12345/v1"
# }
openai_config = { openai_config = {
"api_key": { "api_key": {
"default": "openai_api_key" "default": "openai_api_key"
}, },
"http_proxy": None "http_proxy": None,
"reverse_proxy": None
} }
# [必需] 管理员QQ号用于接收报错等通知及执行管理员级别指令 # [必需] 管理员QQ号用于接收报错等通知及执行管理员级别指令

View File

@ -194,6 +194,11 @@ def start(first_time_init=False):
pkg.openai.dprompt.register_all() pkg.openai.dprompt.register_all()
# 配置openai api_base
if "reverse_proxy" in config.openai_config and config.openai_config["reverse_proxy"] is not None:
import openai
openai.api_base = config.openai_config["reverse_proxy"]
# 主启动流程 # 主启动流程
database = pkg.database.manager.DatabaseManager() database = pkg.database.manager.DatabaseManager()