From 2ebd5421b7f37234dc400ed4f6cf2e6b0c62e0ed Mon Sep 17 00:00:00 2001 From: Parker Date: Fri, 12 Apr 2024 00:28:59 -0500 Subject: [PATCH] Add OPENAI_API_KEY Preparation for autoplay feature using ChatGPT --- code/global_variables.py | 2 ++ code/validate_config.py | 6 +++++- config.ini.example | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/code/global_variables.py b/code/global_variables.py index f79a3bb..1507f7a 100644 --- a/code/global_variables.py +++ b/code/global_variables.py @@ -2,6 +2,7 @@ import configparser import logging from colorlog import ColoredFormatter import discord +import openai log_level = logging.DEBUG @@ -49,6 +50,7 @@ BOT_COLOR = discord.Color(int((config["BOT_INFO"]["BOT_COLOR"]).replace("#", "") FEEDBACK_CHANNEL_ID = int(config["BOT_INFO"]["FEEDBACK_CHANNEL_ID"]) SPOTIFY_CLIENT_ID = config["BOT_INFO"]["SPOTIFY_CLIENT_ID"] SPOTIFY_CLIENT_SECRET = config["BOT_INFO"]["SPOTIFY_CLIENT_SECRET"] +CLIENT = openai.OpenAI(api_key=config["BOT_INFO"]["OPENAI_API_KEY"]) BUG_CHANNEL_ID = int(config["BOT_INFO"]["BUG_CHANNEL_ID"]) BOT_INVITE_LINK = config["BOT_INFO"]["BOT_INVITE_LINK"] diff --git a/code/validate_config.py b/code/validate_config.py index 3db5427..80264e9 100644 --- a/code/validate_config.py +++ b/code/validate_config.py @@ -46,6 +46,10 @@ def validate_config(file_contents): if not config["BOT_INFO"]["SPOTIFY_CLIENT_SECRET"]: LOG.critical("SPOTIFY_CLIENT_SECRET has not been set.") errors += 1 + # Validate OPENAI_API_KEY + if not config["BOT_INFO"]["OPENAI_API_KEY"]: + LOG.critical("OPENAI_API_KEY has not bee set.") + errors += 1 # Validate BUG_CHANNEL_ID if not config["BOT_INFO"]["BUG_CHANNEL_ID"]: LOG.critical("BUG_CHANNEL_ID has not been set.") @@ -107,7 +111,7 @@ def create_config(): "FEEDBACK_CHANNEL_ID": "", "SPOTIFY_CLIENT_ID": "", "SPOTIFY_CLIENT_SECRET": "", - "BUG_CHANNEL_ID": "", + "OPENAI_API_KEY" "BUG_CHANNEL_ID": "", } config["LAVALINK"] = {"HOST": "", "PORT": "", "PASSWORD": ""} diff --git a/config.ini.example b/config.ini.example index 042b04b..c5f2a88 100644 --- a/config.ini.example +++ b/config.ini.example @@ -4,6 +4,7 @@ bot_color = feedback_channel_id = spotify_client_id = spotify_client_secret = +openai_api_key = bug_channel_id = bot_invite_link =