From ce43a54f5ca7c44ba32e77ef6954cc94c9889360 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 14 Mar 2023 17:45:58 +0100 Subject: [PATCH] Argh, more debugging --- reginaldCog/reginald.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/reginaldCog/reginald.py b/reginaldCog/reginald.py index 8134449..ce8756a 100644 --- a/reginaldCog/reginald.py +++ b/reginaldCog/reginald.py @@ -1,14 +1,16 @@ import openai -from redbot.core import commands +from redbot.core import Config, commands from threading import Lock from ratelimit import rate_limited class ReginaldCog(commands.Cog): def __init__(self, bot): self.bot = bot - self.api_key = self.bot.config.get("openai_api_key") - openai.api_key = self.api_key - self.model = self.bot.config.get("openai_model") + self.config = Config.get_conf(self, identifier=1234567890) + self.config.register_global( + openai_api_key="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", + openai_model="text-davinci-002" + ) self.lock = Lock() @rate_limited(1, 10) # Limits command execution to 1 per 10 seconds @@ -20,6 +22,9 @@ class ReginaldCog(commands.Cog): prompt = "Hey," async with ctx.typing(), self.lock: try: + self.api_key = await self.config.openai_api_key() + self.model = await self.config.openai_model() + openai.api_key = self.api_key max_tokens = min(len(prompt) * 2, 2048) response = openai.Completion.create( model=self.model, @@ -35,7 +40,5 @@ class ReginaldCog(commands.Cog): print(f"OpenAI API Error: {e}") def setup(bot): - bot.config.register("openai_api_key", default="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") - bot.config.register("openai_model", default="text-davinci-002") cog = ReginaldCog(bot) - bot.add_cog(cog) \ No newline at end of file + bot.add_cog(cog)