From a99f5c4fb984ae3d5155ea19d63003e046db4bd5 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 18 Mar 2023 17:52:59 +0100 Subject: [PATCH] adding api key set command --- reginaldgptCog/reginaldgpt.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/reginaldgptCog/reginaldgpt.py b/reginaldgptCog/reginaldgpt.py index d58addb..04e1f4a 100644 --- a/reginaldgptCog/reginaldgpt.py +++ b/reginaldgptCog/reginaldgpt.py @@ -5,15 +5,17 @@ import openai class ReginaldGptCog(commands.Cog): def __init__(self, bot): - self.bot = bot self.bot = bot self.config = Config.get_conf(self, identifier=71717171171717) - openai.api_key = os.environ["OPENAI_API_KEY"] + self.config.register_global(api_key=None) @commands.guild_only() @checks.admin_or_permissions(manage_guild=True) async def reginaldgpt(self, ctx, *, message): try: + api_key = await self.config.api_key() + openai.api_key = api_key + response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[ @@ -33,6 +35,14 @@ class ReginaldGptCog(commands.Cog): except Exception as e: await ctx.send("As an AI robot, I errored out.") + @commands.guild_only() + @checks.admin_or_permissions(manage_guild=True) + @commands.command() + async def setreginaldgptapikey(self, ctx, api_key): + await self.config.api_key.set(api_key) + openai.api_key = api_key + await ctx.send("ReginaldGpt API key has been set.") + def setup(bot): cog = ReginaldGptCog(bot) - bot.add_cog(cog) + bot.add_cog(cog) \ No newline at end of file