fix: !gpt !chat API endpoint and API key validation logic

This commit is contained in:
hibobmaster 2023-09-18 12:39:36 +08:00
parent 7fe0ccea8e
commit fe7cc753c4
Signed by: bobmaster
SSH key fingerprint: SHA256:5ZYgd8fg+PcNZNy4SzcSKu5JtqZyBF8kUhY7/k2viDk

View file

@ -222,7 +222,10 @@ class Bot:
content_body = re.sub("\r\n|\r|\n", " ", raw_user_message)
# !gpt command
if self.openai_api_key is not None:
if (
self.openai_api_key is not None
or self.gpt_api_endpoint != "https://api.openai.com/v1/chat/completions"
):
m = self.gpt_prog.match(content_body)
if m:
prompt = m.group(1)
@ -239,12 +242,14 @@ class Bot:
except Exception as e:
logger.error(e, exc_info=True)
if self.gpt_api_endpoint is not None:
# chatgpt
# !chat command
if (
self.openai_api_key is not None
or self.gpt_api_endpoint != "https://api.openai.com/v1/chat/completions"
):
n = self.chat_prog.match(content_body)
if n:
prompt = n.group(1)
if self.openai_api_key is not None:
try:
asyncio.create_task(
self.chat(
@ -257,11 +262,6 @@ class Bot:
)
except Exception as e:
logger.error(e, exc_info=True)
else:
logger.warning("No API_KEY provided")
await send_room_message(
self.client, room_id, reply_message="API_KEY not provided"
)
# lc command
if self.lc_admin is not None: