Format Python code with psf/black push

github-actions 2 years ago
parent 7cb19039a1
commit 4c08ab8820

@ -554,7 +554,7 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
def cleanse_response(self, response_text):
"""Cleans history tokens from response"""
response_text = response_text.replace("GPTie:\n", "")
response_text = response_text.replace(BOT_NAME.replace(" ",""), "")
response_text = response_text.replace(BOT_NAME.replace(" ", ""), "")
response_text = response_text.replace(BOT_NAME, "")
response_text = response_text.replace("<|endofstatement|>", "")
return response_text
@ -828,13 +828,22 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
return
if private:
await ctx.respond(embed=discord.Embed(title=f"{user.name}'s private conversation with GPT3", color=0x808080))
await ctx.respond(
embed=discord.Embed(
title=f"{user.name}'s private conversation with GPT3",
color=0x808080,
)
)
thread = await ctx.channel.create_thread(
name=user.name + "'s private conversation with GPT3",
auto_archive_duration=60,
)
elif not private:
message_thread = await ctx.respond(embed=discord.Embed(title=f"{user.name} 's conversation with GPT3", color=0x808080))
message_thread = await ctx.respond(
embed=discord.Embed(
title=f"{user.name} 's conversation with GPT3", color=0x808080
)
)
# Get the actual message object for the message_thread
message_thread_real = await ctx.fetch_message(message_thread.id)
thread = await message_thread_real.create_thread(
@ -912,12 +921,16 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
overrides = self.conversation_threads[thread.id].get_overrides()
await thread.send(
embed=EmbedStatics.generate_conversation_embed(self.conversation_threads,thread, opener, overrides)
embed=EmbedStatics.generate_conversation_embed(
self.conversation_threads, thread, opener, overrides
)
)
# send opening
if opener:
thread_message = await thread.send(embed=EmbedStatics.generate_opener_embed(opener))
thread_message = await thread.send(
embed=EmbedStatics.generate_opener_embed(opener)
)
if thread.id in self.conversation_threads:
self.awaiting_responses.append(user_id_normalized)
self.awaiting_thread_responses.append(thread.id)
@ -1020,5 +1033,3 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
await self.ask_command(
ctx, message.content, None, None, None, None, from_action=message.content
)

@ -3,6 +3,8 @@ import discord
from services.environment_service import EnvService
BOT_NAME = EnvService.get_custom_bot_name()
class EmbedStatics:
def __init__(self):
pass
@ -79,4 +81,4 @@ class EmbedStatics:
description=f"{opener}",
color=0x808080,
)
return embed
return embed

@ -14,6 +14,7 @@ from services.environment_service import EnvService
BOT_NAME = EnvService.get_custom_bot_name()
class TextService:
def __init__(self):
pass
@ -62,7 +63,7 @@ class TextService:
from_action (bool, optional): If the function is being called from a message action. Defaults to False.
"""
new_prompt = (
prompt + "\n"+BOT_NAME
prompt + "\n" + BOT_NAME
if not from_ask_command and not from_edit_command
else prompt
)
@ -84,7 +85,7 @@ class TextService:
):
# Delete "GPTie: <|endofstatement|>" from the user's conversation history if it exists
for item in converser_cog.conversation_threads[ctx.channel.id].history:
if item.text.strip() == BOT_NAME+"<|endofstatement|>":
if item.text.strip() == BOT_NAME + "<|endofstatement|>":
converser_cog.conversation_threads[
ctx.channel.id
].history.remove(item)
@ -197,7 +198,7 @@ class TextService:
[item.text for item in prompt_with_history]
)
new_prompt = prompt_with_history + "\n"+BOT_NAME
new_prompt = prompt_with_history + "\n" + BOT_NAME
tokens = converser_cog.usage_service.count_tokens(new_prompt)
@ -230,7 +231,8 @@ class TextService:
].history
]
)
+ "\n"+BOT_NAME
+ "\n"
+ BOT_NAME
)
tokens = converser_cog.usage_service.count_tokens(new_prompt)
@ -302,7 +304,11 @@ class TextService:
if not redo_request:
converser_cog.conversation_threads[id].history.append(
EmbeddedConversationItem(
"\n"+BOT_NAME + str(response_text) + "<|endofstatement|>\n", 0
"\n"
+ BOT_NAME
+ str(response_text)
+ "<|endofstatement|>\n",
0,
)
)
@ -317,7 +323,7 @@ class TextService:
# Create an embedding and timestamp for the prompt
response_text = (
"\n"+BOT_NAME + str(response_text) + "<|endofstatement|>\n"
"\n" + BOT_NAME + str(response_text) + "<|endofstatement|>\n"
)
response_text = response_text.encode("ascii", "ignore").decode()
@ -468,7 +474,7 @@ class TextService:
# Error catching for AIOHTTP Errors
except aiohttp.ClientResponseError as e:
embed=EmbedStatics.get_invalid_api_response_embed(e)
embed = EmbedStatics.get_invalid_api_response_embed(e)
if from_context:
await ctx.send_followup(embed=embed)
else:
@ -543,9 +549,12 @@ class TextService:
# Since this is async, we don't want to allow the user to send another prompt while a conversation
# prompt is processing, that'll mess up the conversation history!
if message.author.id in converser_cog.awaiting_responses:
message = await message.reply(embed=discord.Embed(
title=f"You are already waiting for a response, please wait and speak afterwards.",
color=0x808080))
message = await message.reply(
embed=discord.Embed(
title=f"You are already waiting for a response, please wait and speak afterwards.",
color=0x808080,
)
)
# get the current date, add 10 seconds to it, and then turn it into a timestamp.
# we need to use our deletion service because this isn't an interaction, it's a regular message.
@ -560,8 +569,12 @@ class TextService:
return
if message.channel.id in converser_cog.awaiting_thread_responses:
message = await message.reply(embed=discord.Embed(title=f"This thread is already waiting for a response, please wait and speak afterwards.", color=0x808080))
message = await message.reply(
embed=discord.Embed(
title=f"This thread is already waiting for a response, please wait and speak afterwards.",
color=0x808080,
)
)
# get the current date, add 10 seconds to it, and then turn it into a timestamp.
# we need to use our deletion service because this isn't an interaction, it's a regular message.

Loading…
Cancel
Save