|
|
@ -889,14 +889,20 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
|
|
|
|
edited_request=False,
|
|
|
|
edited_request=False,
|
|
|
|
redo_request=False,
|
|
|
|
redo_request=False,
|
|
|
|
):
|
|
|
|
):
|
|
|
|
new_prompt = prompt + "\nGPTie: " if not from_g_command and not from_edit_command else prompt
|
|
|
|
new_prompt = (
|
|
|
|
|
|
|
|
prompt + "\nGPTie: "
|
|
|
|
|
|
|
|
if not from_g_command and not from_edit_command
|
|
|
|
|
|
|
|
else prompt
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
from_context = isinstance(ctx, discord.ApplicationContext)
|
|
|
|
from_context = isinstance(ctx, discord.ApplicationContext)
|
|
|
|
|
|
|
|
|
|
|
|
if not instruction:
|
|
|
|
if not instruction:
|
|
|
|
tokens = self.usage_service.count_tokens(new_prompt)
|
|
|
|
tokens = self.usage_service.count_tokens(new_prompt)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
tokens = self.usage_service.count_tokens(new_prompt) + self.usage_service.count_tokens(instruction)
|
|
|
|
tokens = self.usage_service.count_tokens(
|
|
|
|
|
|
|
|
new_prompt
|
|
|
|
|
|
|
|
) + self.usage_service.count_tokens(instruction)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
|
@ -1089,9 +1095,9 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
|
|
|
|
response_text = self.cleanse_response(str(response["choices"][0]["text"]))
|
|
|
|
response_text = self.cleanse_response(str(response["choices"][0]["text"]))
|
|
|
|
|
|
|
|
|
|
|
|
if from_g_command:
|
|
|
|
if from_g_command:
|
|
|
|
# Append the prompt to the beginning of the response, in italics, then a new line
|
|
|
|
# Append the prompt to the beginning of the response, in italics, then a new line
|
|
|
|
response_text = response_text.strip()
|
|
|
|
response_text = response_text.strip()
|
|
|
|
response_text = f"***{prompt}***\n\n{response_text}"
|
|
|
|
response_text = f"***{prompt}***\n\n{response_text}"
|
|
|
|
elif from_edit_command:
|
|
|
|
elif from_edit_command:
|
|
|
|
if codex:
|
|
|
|
if codex:
|
|
|
|
response_text = response_text.strip()
|
|
|
|
response_text = response_text.strip()
|
|
|
@ -1164,21 +1170,34 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
|
|
|
|
response_message = await ctx.reply(
|
|
|
|
response_message = await ctx.reply(
|
|
|
|
response_text,
|
|
|
|
response_text,
|
|
|
|
view=ConversationView(
|
|
|
|
view=ConversationView(
|
|
|
|
ctx, self, ctx.channel.id, model, custom_api_key=custom_api_key
|
|
|
|
ctx,
|
|
|
|
|
|
|
|
self,
|
|
|
|
|
|
|
|
ctx.channel.id,
|
|
|
|
|
|
|
|
model,
|
|
|
|
|
|
|
|
custom_api_key=custom_api_key,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
elif from_edit_command:
|
|
|
|
elif from_edit_command:
|
|
|
|
response_message = await ctx.respond(
|
|
|
|
response_message = await ctx.respond(
|
|
|
|
response_text,
|
|
|
|
response_text,
|
|
|
|
view=ConversationView(
|
|
|
|
view=ConversationView(
|
|
|
|
ctx, self, ctx.channel.id, model, from_edit_command, custom_api_key=custom_api_key
|
|
|
|
ctx,
|
|
|
|
|
|
|
|
self,
|
|
|
|
|
|
|
|
ctx.channel.id,
|
|
|
|
|
|
|
|
model,
|
|
|
|
|
|
|
|
from_edit_command,
|
|
|
|
|
|
|
|
custom_api_key=custom_api_key,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
response_message = await ctx.respond(
|
|
|
|
response_message = await ctx.respond(
|
|
|
|
response_text,
|
|
|
|
response_text,
|
|
|
|
view=ConversationView(
|
|
|
|
view=ConversationView(
|
|
|
|
ctx, self, ctx.channel.id, model, custom_api_key=custom_api_key
|
|
|
|
ctx,
|
|
|
|
|
|
|
|
self,
|
|
|
|
|
|
|
|
ctx.channel.id,
|
|
|
|
|
|
|
|
model,
|
|
|
|
|
|
|
|
custom_api_key=custom_api_key,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -1190,7 +1209,12 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
self.redo_users[ctx.author.id] = RedoUser(
|
|
|
|
self.redo_users[ctx.author.id] = RedoUser(
|
|
|
|
prompt=new_prompt, instruction=instruction, ctx=ctx, message=ctx, response=actual_response_message, codex=codex
|
|
|
|
prompt=new_prompt,
|
|
|
|
|
|
|
|
instruction=instruction,
|
|
|
|
|
|
|
|
ctx=ctx,
|
|
|
|
|
|
|
|
message=ctx,
|
|
|
|
|
|
|
|
response=actual_response_message,
|
|
|
|
|
|
|
|
codex=codex,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.redo_users[ctx.author.id].add_interaction(
|
|
|
|
self.redo_users[ctx.author.id].add_interaction(
|
|
|
|
actual_response_message.id
|
|
|
|
actual_response_message.id
|
|
|
@ -1219,7 +1243,9 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
|
|
|
|
await ctx.send_followup(message)
|
|
|
|
await ctx.send_followup(message)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await ctx.reply(message)
|
|
|
|
await ctx.reply(message)
|
|
|
|
self.remove_awaiting(ctx.author.id, ctx.channel.id, from_g_command, from_edit_command)
|
|
|
|
self.remove_awaiting(
|
|
|
|
|
|
|
|
ctx.author.id, ctx.channel.id, from_g_command, from_edit_command
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Error catching for OpenAI model value errors
|
|
|
|
# Error catching for OpenAI model value errors
|
|
|
|
except ValueError as e:
|
|
|
|
except ValueError as e:
|
|
|
@ -1227,7 +1253,9 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
|
|
|
|
await ctx.send_followup(e)
|
|
|
|
await ctx.send_followup(e)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await ctx.reply(e)
|
|
|
|
await ctx.reply(e)
|
|
|
|
self.remove_awaiting(ctx.author.id, ctx.channel.id, from_g_command, from_edit_command)
|
|
|
|
self.remove_awaiting(
|
|
|
|
|
|
|
|
ctx.author.id, ctx.channel.id, from_g_command, from_edit_command
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# General catch case for everything
|
|
|
|
# General catch case for everything
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
@ -1236,7 +1264,9 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
|
|
|
|
await ctx.send_followup(message) if from_context else await ctx.reply(
|
|
|
|
await ctx.send_followup(message) if from_context else await ctx.reply(
|
|
|
|
message
|
|
|
|
message
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.remove_awaiting(ctx.author.id, ctx.channel.id, from_g_command, from_edit_command)
|
|
|
|
self.remove_awaiting(
|
|
|
|
|
|
|
|
ctx.author.id, ctx.channel.id, from_g_command, from_edit_command
|
|
|
|
|
|
|
|
)
|
|
|
|
traceback.print_exc()
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -1318,6 +1348,7 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
|
|
|
|
from_g_command=True,
|
|
|
|
from_g_command=True,
|
|
|
|
custom_api_key=user_api_key,
|
|
|
|
custom_api_key=user_api_key,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@add_to_group("gpt")
|
|
|
|
@add_to_group("gpt")
|
|
|
|
@discord.slash_command(
|
|
|
|
@discord.slash_command(
|
|
|
|
name="edit",
|
|
|
|
name="edit",
|
|
|
@ -1325,10 +1356,15 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
|
|
|
|
guild_ids=ALLOWED_GUILDS,
|
|
|
|
guild_ids=ALLOWED_GUILDS,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@discord.option(
|
|
|
|
@discord.option(
|
|
|
|
name="instruction", description="How you want GPT3 to edit the text", required=True
|
|
|
|
name="instruction",
|
|
|
|
|
|
|
|
description="How you want GPT3 to edit the text",
|
|
|
|
|
|
|
|
required=True,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@discord.option(
|
|
|
|
@discord.option(
|
|
|
|
name="input", description="The text you want to edit, can be empty", required=False, default=""
|
|
|
|
name="input",
|
|
|
|
|
|
|
|
description="The text you want to edit, can be empty",
|
|
|
|
|
|
|
|
required=False,
|
|
|
|
|
|
|
|
default="",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@discord.option(
|
|
|
|
@discord.option(
|
|
|
|
name="temperature",
|
|
|
|
name="temperature",
|
|
|
@ -1347,10 +1383,7 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
|
|
|
|
max_value=1,
|
|
|
|
max_value=1,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@discord.option(
|
|
|
|
@discord.option(
|
|
|
|
name="codex",
|
|
|
|
name="codex", description="Enable codex version", required=False, default=False
|
|
|
|
description="Enable codex version",
|
|
|
|
|
|
|
|
required=False,
|
|
|
|
|
|
|
|
default=False
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@discord.guild_only()
|
|
|
|
@discord.guild_only()
|
|
|
|
async def edit(
|
|
|
|
async def edit(
|
|
|
@ -1367,7 +1400,6 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
|
|
|
|
input = await self.mention_to_username(ctx, input.strip())
|
|
|
|
input = await self.mention_to_username(ctx, input.strip())
|
|
|
|
instruction = await self.mention_to_username(ctx, instruction.strip())
|
|
|
|
instruction = await self.mention_to_username(ctx, instruction.strip())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user_api_key = None
|
|
|
|
user_api_key = None
|
|
|
|
if USER_INPUT_API_KEYS:
|
|
|
|
if USER_INPUT_API_KEYS:
|
|
|
|
user_api_key = await GPT3ComCon.get_user_api_key(user.id, ctx)
|
|
|
|
user_api_key = await GPT3ComCon.get_user_api_key(user.id, ctx)
|
|
|
@ -1795,7 +1827,15 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ConversationView(discord.ui.View):
|
|
|
|
class ConversationView(discord.ui.View):
|
|
|
|
def __init__(self, ctx, converser_cog, id, model, from_edit_command=False, custom_api_key=None):
|
|
|
|
def __init__(
|
|
|
|
|
|
|
|
self,
|
|
|
|
|
|
|
|
ctx,
|
|
|
|
|
|
|
|
converser_cog,
|
|
|
|
|
|
|
|
id,
|
|
|
|
|
|
|
|
model,
|
|
|
|
|
|
|
|
from_edit_command=False,
|
|
|
|
|
|
|
|
custom_api_key=None,
|
|
|
|
|
|
|
|
):
|
|
|
|
super().__init__(timeout=3600) # 1 hour interval to redo.
|
|
|
|
super().__init__(timeout=3600) # 1 hour interval to redo.
|
|
|
|
self.converser_cog = converser_cog
|
|
|
|
self.converser_cog = converser_cog
|
|
|
|
self.ctx = ctx
|
|
|
|
self.ctx = ctx
|
|
|
@ -1803,7 +1843,12 @@ class ConversationView(discord.ui.View):
|
|
|
|
self.from_edit_command = from_edit_command
|
|
|
|
self.from_edit_command = from_edit_command
|
|
|
|
self.custom_api_key = custom_api_key
|
|
|
|
self.custom_api_key = custom_api_key
|
|
|
|
self.add_item(
|
|
|
|
self.add_item(
|
|
|
|
RedoButton(self.converser_cog, model, from_edit_command, custom_api_key=self.custom_api_key)
|
|
|
|
RedoButton(
|
|
|
|
|
|
|
|
self.converser_cog,
|
|
|
|
|
|
|
|
model,
|
|
|
|
|
|
|
|
from_edit_command,
|
|
|
|
|
|
|
|
custom_api_key=self.custom_api_key,
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if id in self.converser_cog.conversation_threads:
|
|
|
|
if id in self.converser_cog.conversation_threads:
|
|
|
@ -1890,7 +1935,7 @@ class RedoButton(discord.ui.Button["ConversationView"]):
|
|
|
|
codex=codex,
|
|
|
|
codex=codex,
|
|
|
|
custom_api_key=self.custom_api_key,
|
|
|
|
custom_api_key=self.custom_api_key,
|
|
|
|
redo_request=True,
|
|
|
|
redo_request=True,
|
|
|
|
from_edit_command=self.from_edit_command
|
|
|
|
from_edit_command=self.from_edit_command,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await interaction.response.send_message(
|
|
|
|
await interaction.response.send_message(
|
|
|
|