From e5099e1daa8d963a4fbfb479db67420e0e70e1a5 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Wed, 5 Jul 2023 20:05:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=81=E5=B0=91=E6=95=B0=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=EF=BC=8Copenai=E7=9A=84=E5=AE=98=E6=96=B9KEY=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E4=BC=B4=E9=9A=8F=E7=BB=84=E7=BB=87=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 4 ++++ request_llm/bridge_chatgpt.py | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index a3c1685..8a69f36 100644 --- a/config.py +++ b/config.py @@ -99,6 +99,10 @@ AUTHENTICATION = [] CUSTOM_PATH = "/" +# 极少数情况下,openai的官方KEY需要伴随组织编码(格式如org-xxxxxxxxxxxxxxxxxxxxxxxx)使用 +API_ORG = "" + + # 如果需要使用Slack Claude,使用教程详情见 request_llm/README.md SLACK_CLAUDE_BOT_ID = '' SLACK_CLAUDE_USER_TOKEN = '' diff --git a/request_llm/bridge_chatgpt.py b/request_llm/bridge_chatgpt.py index c46cac1..5833c05 100644 --- a/request_llm/bridge_chatgpt.py +++ b/request_llm/bridge_chatgpt.py @@ -22,8 +22,8 @@ import importlib # config_private.py放自己的秘密如API和代理网址 # 读取时首先看是否存在私密的config_private配置文件(不受git管控),如果有,则覆盖原config文件 from toolbox import get_conf, update_ui, is_any_api_key, select_api_key, what_keys, clip_history, trimmed_format_exc -proxies, API_KEY, TIMEOUT_SECONDS, MAX_RETRY = \ - get_conf('proxies', 'API_KEY', 'TIMEOUT_SECONDS', 'MAX_RETRY') +proxies, API_KEY, TIMEOUT_SECONDS, MAX_RETRY, API_ORG = \ + get_conf('proxies', 'API_KEY', 'TIMEOUT_SECONDS', 'MAX_RETRY', 'API_ORG') timeout_bot_msg = '[Local Message] Request timeout. Network error. Please check proxy settings in config.py.' + \ '网络错误,检查代理服务器是否可用,以及代理设置的格式是否正确,格式须是[协议]://[地址]:[端口],缺一不可。' @@ -246,6 +246,7 @@ def generate_payload(inputs, llm_kwargs, history, system_prompt, stream): "Content-Type": "application/json", "Authorization": f"Bearer {api_key}" } + if API_ORG.startswith('org-'): headers.update({"org": API_ORG}) conversation_cnt = len(history) // 2