Format Python code with psf/black push

github-actions 2 years ago
parent 3775432aae
commit db7c400ca4

@ -827,15 +827,15 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
guild_ids=ALLOWED_GUILDS,
)
@discord.option(
name="opener",
description="Which sentence to start with, added after the file",
name="opener",
description="Which sentence to start with, added after the file",
required=False,
)
@discord.option(
name="opener_file",
description="Which file to start with, added before the opener, sets minimal starter",
required=False,
autocomplete=File_autocompleter.get_openers
name="opener_file",
description="Which file to start with, added before the opener, sets minimal starter",
required=False,
autocomplete=File_autocompleter.get_openers,
)
@discord.option(
name="private",
@ -851,7 +851,12 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
)
@discord.guild_only()
async def converse(
self, ctx: discord.ApplicationContext, opener: str, opener_file: str, private, minimal
self,
ctx: discord.ApplicationContext,
opener: str,
opener_file: str,
private,
minimal,
):
if private:
await ctx.defer(ephemeral=True)
@ -871,12 +876,16 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
user_id_normalized = user.id
else:
user_id_normalized = ctx.author.id
if opener_file: # only load in files if it's included in the command, if not pass on as normal
if (
opener_file
): # only load in files if it's included in the command, if not pass on as normal
if opener_file.endswith(".txt"):
# Load the file and read it into opener
opener_file = f"openers{separator}{opener_file}"
opener_file = await self.load_file(opener_file, ctx)
if not opener: # if we only use opener_file then only pass on opener_file for the opening prompt
if (
not opener
): # if we only use opener_file then only pass on opener_file for the opening prompt
opener = opener_file
else:
opener = opener_file + opener
@ -991,13 +1000,13 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
name="parameter",
description="The setting to change",
required=False,
autocomplete=Settings_autocompleter.get_settings
autocomplete=Settings_autocompleter.get_settings,
)
@discord.option(
name="value",
description="The value to set the setting to",
required=False,
autocomplete=Settings_autocompleter.get_value
autocomplete=Settings_autocompleter.get_value,
)
@discord.guild_only()
async def settings(

@ -10,28 +10,46 @@ usage_service = UsageService(Path(os.environ.get("DATA_DIR", os.getcwd())))
model = Model(usage_service)
class Settings_autocompleter:
class Settings_autocompleter:
async def get_settings(ctx: discord.AutocompleteContext):
SETTINGS = [re.sub("^_","",key) for key in model.__dict__.keys() if key not in model._hidden_attributes]
return [parameter for parameter in SETTINGS if parameter.startswith(ctx.value.lower())][:25]
async def get_value(ctx: discord.AutocompleteContext): # Behaves a bit weird if you go back and edit the parameter without typing in a new command
SETTINGS = [
re.sub("^_", "", key)
for key in model.__dict__.keys()
if key not in model._hidden_attributes
]
return [
parameter
for parameter in SETTINGS
if parameter.startswith(ctx.value.lower())
][:25]
async def get_value(
ctx: discord.AutocompleteContext,
): # Behaves a bit weird if you go back and edit the parameter without typing in a new command
values = {
'mode' : ['temperature', 'top_p'],
'model' : ["text-davinci-003", "text-curie-001"],
'low_usage_mode' : ["True", "False"],
'image_size' : ["256x256", "512x512", "1024x1024"],
'summarize_conversastion' : ["True", "False"],
'welcome_message_enabled' : ["True", "False"]
"mode": ["temperature", "top_p"],
"model": ["text-davinci-003", "text-curie-001"],
"low_usage_mode": ["True", "False"],
"image_size": ["256x256", "512x512", "1024x1024"],
"summarize_conversastion": ["True", "False"],
"welcome_message_enabled": ["True", "False"],
}
if ctx.options["parameter"] in values.keys():
return[value for value in values[ctx.options["parameter"]]]
return [value for value in values[ctx.options["parameter"]]]
else:
await ctx.interaction.response.defer() # defer so the autocomplete in int values doesn't error but rather just says not found
await ctx.interaction.response.defer() # defer so the autocomplete in int values doesn't error but rather just says not found
return []
class File_autocompleter:
async def get_openers(ctx: discord.AutocompleteContext):
try:
return [file for file in os.listdir('openers') if file.startswith(ctx.value.lower())][:25] # returns the 25 first files from your current input
return [
file
for file in os.listdir("openers")
if file.startswith(ctx.value.lower())
][
:25
] # returns the 25 first files from your current input
except:
return ["No 'openers' folder"]
return ["No 'openers' folder"]

Loading…
Cancel
Save