From 2c8da59b472148e8c409973797c5bacb38d6a862 Mon Sep 17 00:00:00 2001 From: B1gM8c <89020353+B1gM8c@users.noreply.github.com> Date: Wed, 15 Mar 2023 00:14:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89op?= =?UTF-8?q?enai=5Fapi=5Fbase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持自定义openai_api_base 解决国内API被墙的问题,可以自定义使用自己的中转API --- bot/chatgpt/chat_gpt_bot.py | 1 + bot/openai/open_ai_bot.py | 1 + config-template.json | 1 + 3 files changed, 3 insertions(+) diff --git a/bot/chatgpt/chat_gpt_bot.py b/bot/chatgpt/chat_gpt_bot.py index 78e344f..1898d05 100644 --- a/bot/chatgpt/chat_gpt_bot.py +++ b/bot/chatgpt/chat_gpt_bot.py @@ -16,6 +16,7 @@ else: class ChatGPTBot(Bot): def __init__(self): openai.api_key = conf().get('open_ai_api_key') + openai.api_base = conf().get('open_ai_api_base') proxy = conf().get('proxy') if proxy: openai.proxy = proxy diff --git a/bot/openai/open_ai_bot.py b/bot/openai/open_ai_bot.py index c948a7c..1c12989 100644 --- a/bot/openai/open_ai_bot.py +++ b/bot/openai/open_ai_bot.py @@ -12,6 +12,7 @@ user_session = dict() class OpenAIBot(Bot): def __init__(self): openai.api_key = conf().get('open_ai_api_key') + openai.api_base = conf().get('open_ai_api_base') def reply(self, query, context=None): diff --git a/config-template.json b/config-template.json index 9ad9f5d..87fbc00 100644 --- a/config-template.json +++ b/config-template.json @@ -1,5 +1,6 @@ { "open_ai_api_key": "YOUR API KEY", + "open_ai_api_base":"", "proxy": "", "single_chat_prefix": ["bot", "@bot"], "single_chat_reply_prefix": "[bot] ",