From dba7c861d5862c1acb9a91e1952516f49214cff0 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Mar 2023 00:03:31 +0100 Subject: [PATCH] Debugging --- reginaldCog/reginald.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/reginaldCog/reginald.py b/reginaldCog/reginald.py index f10ac8b..b9d3ce2 100644 --- a/reginaldCog/reginald.py +++ b/reginaldCog/reginald.py @@ -1,4 +1,6 @@ -import openai +import discord +import json +import openai_async as openai import os import random import requests @@ -8,6 +10,7 @@ from io import BytesIO from PIL import Image from redbot.core import Config, commands + class ReginaldCog(commands.Cog): def __init__(self, bot): self.bot = bot @@ -25,10 +28,13 @@ class ReginaldCog(commands.Cog): return any(role.id == kanium_role_id for role in ctx.author.roles) return commands.check(predicate) - def has_janitor_role(): + + def has_janitor_or_admin_role(): async def predicate(ctx): janitor_role_id = 672156832323600396 - return any(role.id == janitor_role_id for role in ctx.author.roles) + has_janitor_role = any(role.id == janitor_role_id for role in ctx.author.roles) + has_admin_permission = ctx.author.guild_permissions.administrator + return has_janitor_role or has_admin_permission return commands.check(predicate) @@ -78,17 +84,18 @@ class ReginaldCog(commands.Cog): openai.api_key = api_key max_tokens = 1000 temperature = 0.5 - response = openai.Completion.create( + response = await openai.Completion.create( model=model, prompt=prompt, max_tokens=max_tokens, n=1, stop=None, temperature=temperature, - presence_penalty=0.2, - frequency_penalty=0.1, + presence_penalty=0.5, + frequency_penalty=0.5, best_of=3 ) + return response.choices[0].text.strip() @staticmethod @@ -103,7 +110,7 @@ class ReginaldCog(commands.Cog): return chunks @commands.guild_only() - @has_janitor_role() + @has_janitor_or_admin_role() @commands.command(help="Ask Reginald to generate an image based on a prompt") @commands.cooldown(1, 300, commands.BucketType.user) # 5-minute cooldown per user async def reginaldimagine(self, ctx, *, prompt=None):