|
|
@ -11,6 +11,7 @@ from models.deletion_service_model import Deletion
|
|
|
|
from models.env_service_model import EnvService
|
|
|
|
from models.env_service_model import EnvService
|
|
|
|
from models.message_model import Message
|
|
|
|
from models.message_model import Message
|
|
|
|
from models.user_model import User, RedoUser
|
|
|
|
from models.user_model import User, RedoUser
|
|
|
|
|
|
|
|
from models.check_model import Check
|
|
|
|
from collections import defaultdict
|
|
|
|
from collections import defaultdict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -37,7 +38,6 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"):
|
|
|
|
self._last_member_ = None
|
|
|
|
self._last_member_ = None
|
|
|
|
self.conversating_users = {}
|
|
|
|
self.conversating_users = {}
|
|
|
|
self.DAVINCI_ROLES = ["admin", "Admin", "GPT", "gpt"]
|
|
|
|
self.DAVINCI_ROLES = ["admin", "Admin", "GPT", "gpt"]
|
|
|
|
self.ALLOWED_ROLES = EnvService.get_allowed_roles()
|
|
|
|
|
|
|
|
self.END_PROMPTS = [
|
|
|
|
self.END_PROMPTS = [
|
|
|
|
"end",
|
|
|
|
"end",
|
|
|
|
"end conversation",
|
|
|
|
"end conversation",
|
|
|
@ -83,12 +83,6 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"):
|
|
|
|
self.message_queue = message_queue
|
|
|
|
self.message_queue = message_queue
|
|
|
|
self.conversation_threads = {}
|
|
|
|
self.conversation_threads = {}
|
|
|
|
|
|
|
|
|
|
|
|
async def check_valid_roles(self, user, ctx):
|
|
|
|
|
|
|
|
if not any(role.name in self.ALLOWED_ROLES for role in user.roles):
|
|
|
|
|
|
|
|
await ctx.respond("You don't have permission to use this.")
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@commands.Cog.listener()
|
|
|
|
@commands.Cog.listener()
|
|
|
|
async def on_member_remove(self, member):
|
|
|
|
async def on_member_remove(self, member):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
@ -101,7 +95,9 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"):
|
|
|
|
print(f"The debug channel was acquired")
|
|
|
|
print(f"The debug channel was acquired")
|
|
|
|
|
|
|
|
|
|
|
|
@discord.slash_command(
|
|
|
|
@discord.slash_command(
|
|
|
|
name="set-usage", description="Set the current OpenAI usage (in dollars)"
|
|
|
|
name="set-usage",
|
|
|
|
|
|
|
|
description="Set the current OpenAI usage (in dollars)",
|
|
|
|
|
|
|
|
checks=[Check.check_valid_roles()],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@discord.option(
|
|
|
|
@discord.option(
|
|
|
|
name="usage_amount",
|
|
|
|
name="usage_amount",
|
|
|
@ -111,9 +107,6 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"):
|
|
|
|
async def set_usage(self, ctx, usage_amount: float):
|
|
|
|
async def set_usage(self, ctx, usage_amount: float):
|
|
|
|
await ctx.defer()
|
|
|
|
await ctx.defer()
|
|
|
|
|
|
|
|
|
|
|
|
if not await self.check_valid_roles(ctx.user, ctx):
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Attempt to convert the input usage value into a float
|
|
|
|
# Attempt to convert the input usage value into a float
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
usage = float(usage_amount)
|
|
|
|
usage = float(usage_amount)
|
|
|
@ -126,12 +119,10 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"):
|
|
|
|
@discord.slash_command(
|
|
|
|
@discord.slash_command(
|
|
|
|
name="delete-conversation-threads",
|
|
|
|
name="delete-conversation-threads",
|
|
|
|
description="Delete all conversation threads across the bot servers.",
|
|
|
|
description="Delete all conversation threads across the bot servers.",
|
|
|
|
|
|
|
|
checks=[Check.check_valid_roles()],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
async def delete_all_conversation_threads(self, ctx):
|
|
|
|
async def delete_all_conversation_threads(self, ctx):
|
|
|
|
await ctx.defer()
|
|
|
|
await ctx.defer()
|
|
|
|
# If the user has ADMIN_ROLES
|
|
|
|
|
|
|
|
if not await self.check_valid_roles(ctx.user, ctx):
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for guild in self.bot.guilds:
|
|
|
|
for guild in self.bot.guilds:
|
|
|
|
for thread in guild.threads:
|
|
|
|
for thread in guild.threads:
|
|
|
@ -626,7 +617,10 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"):
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
@discord.slash_command(
|
|
|
|
@discord.slash_command(
|
|
|
|
name="g", description="Ask GPT3 something!", guild_ids=ALLOWED_GUILDS
|
|
|
|
name="g",
|
|
|
|
|
|
|
|
description="Ask GPT3 something!",
|
|
|
|
|
|
|
|
guild_ids=ALLOWED_GUILDS,
|
|
|
|
|
|
|
|
checks=[Check.check_valid_roles()],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@discord.option(
|
|
|
|
@discord.option(
|
|
|
|
name="prompt", description="The prompt to send to GPT3", required=True
|
|
|
|
name="prompt", description="The prompt to send to GPT3", required=True
|
|
|
@ -638,9 +632,6 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"):
|
|
|
|
user = ctx.user
|
|
|
|
user = ctx.user
|
|
|
|
prompt = prompt.strip()
|
|
|
|
prompt = prompt.strip()
|
|
|
|
|
|
|
|
|
|
|
|
if not await self.check_valid_roles(user, ctx):
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# CONVERSE Checks here TODO
|
|
|
|
# CONVERSE Checks here TODO
|
|
|
|
# Send the request to the model
|
|
|
|
# Send the request to the model
|
|
|
|
# If conversing, the prompt to send is the history, otherwise, it's just the prompt
|
|
|
|
# If conversing, the prompt to send is the history, otherwise, it's just the prompt
|
|
|
@ -657,14 +648,12 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"):
|
|
|
|
name="chat-gpt",
|
|
|
|
name="chat-gpt",
|
|
|
|
description="Have a conversation with GPT3",
|
|
|
|
description="Have a conversation with GPT3",
|
|
|
|
guild_ids=ALLOWED_GUILDS,
|
|
|
|
guild_ids=ALLOWED_GUILDS,
|
|
|
|
|
|
|
|
checks=[Check.check_valid_roles()],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@discord.guild_only()
|
|
|
|
@discord.guild_only()
|
|
|
|
async def chat_gpt(self, ctx: discord.ApplicationContext):
|
|
|
|
async def chat_gpt(self, ctx: discord.ApplicationContext):
|
|
|
|
await ctx.defer()
|
|
|
|
await ctx.defer()
|
|
|
|
|
|
|
|
|
|
|
|
if not await self.check_valid_roles(ctx.user, ctx):
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user = ctx.user
|
|
|
|
user = ctx.user
|
|
|
|
|
|
|
|
|
|
|
|
if user.id in self.conversating_users:
|
|
|
|
if user.id in self.conversating_users:
|
|
|
@ -730,7 +719,28 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"):
|
|
|
|
guild_ids=ALLOWED_GUILDS,
|
|
|
|
guild_ids=ALLOWED_GUILDS,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@discord.option(
|
|
|
|
@discord.option(
|
|
|
|
name="parameter", description="The setting to change", required=False
|
|
|
|
name="parameter",
|
|
|
|
|
|
|
|
description="The setting to change",
|
|
|
|
|
|
|
|
required=False,
|
|
|
|
|
|
|
|
choices=[
|
|
|
|
|
|
|
|
"mode",
|
|
|
|
|
|
|
|
"temp",
|
|
|
|
|
|
|
|
"top_p",
|
|
|
|
|
|
|
|
"max_tokens",
|
|
|
|
|
|
|
|
"presence_penalty",
|
|
|
|
|
|
|
|
"frequency_penalty",
|
|
|
|
|
|
|
|
"best_of",
|
|
|
|
|
|
|
|
"prompt_min_length",
|
|
|
|
|
|
|
|
"max_conversation_length",
|
|
|
|
|
|
|
|
"model",
|
|
|
|
|
|
|
|
"low_usage_mode",
|
|
|
|
|
|
|
|
"image_size",
|
|
|
|
|
|
|
|
"num_images",
|
|
|
|
|
|
|
|
"summarize_conversations",
|
|
|
|
|
|
|
|
"summarize_threshold",
|
|
|
|
|
|
|
|
"IMAGE_SAVE_PATH",
|
|
|
|
|
|
|
|
"openai_key",
|
|
|
|
|
|
|
|
],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@discord.option(
|
|
|
|
@discord.option(
|
|
|
|
name="value", description="The value to set the setting to", required=False
|
|
|
|
name="value", description="The value to set the setting to", required=False
|
|
|
|