more debug debugging

This commit is contained in:
unknown 2023-03-14 17:54:14 +01:00
parent ce43a54f5c
commit 98004a67dd

View File

@ -1,7 +1,5 @@
import openai import openai
from redbot.core import Config, commands from redbot.core import Config, commands
from threading import Lock
from ratelimit import rate_limited
class ReginaldCog(commands.Cog): class ReginaldCog(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
@ -11,23 +9,21 @@ class ReginaldCog(commands.Cog):
openai_api_key="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", openai_api_key="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",
openai_model="text-davinci-002" openai_model="text-davinci-002"
) )
self.lock = Lock()
@rate_limited(1, 10) # Limits command execution to 1 per 10 seconds @commands.guild_only()
@commands.has_permissions(manage_guild=True)
@commands.command() @commands.command()
@commands.has_permissions(administrator=True)
async def reginald(self, ctx, *, prompt=None): async def reginald(self, ctx, *, prompt=None):
"""Ask Reginald a question""" """Ask Reginald a question"""
if prompt is None: if prompt is None:
prompt = "Hey," prompt = "Hey,"
async with ctx.typing(), self.lock:
try: try:
self.api_key = await self.config.openai_api_key() api_key = await self.config.openai_api_key()
self.model = await self.config.openai_model() model = await self.config.openai_model()
openai.api_key = self.api_key openai.api_key = api_key
max_tokens = min(len(prompt) * 2, 2048) max_tokens = min(len(prompt) * 2, 2048)
response = openai.Completion.create( response = openai.Completion.create(
model=self.model, model=model,
prompt=prompt, prompt=prompt,
max_tokens=max_tokens, max_tokens=max_tokens,
n=1, n=1,