Format Python code with psf/black push

github-actions 1 year ago
parent 2380e970c6
commit 69e48062e1

@ -251,10 +251,12 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
return
if normalized_user_id in self.awaiting_responses:
await ctx.reply(embed=discord.Embed(
title=f"Please wait for a response before ending the conversation.",
color=0x808080,
))
await ctx.reply(
embed=discord.Embed(
title=f"Please wait for a response before ending the conversation.",
color=0x808080,
)
)
return
except Exception:
@ -291,7 +293,10 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
delete_after=10,
)
await ctx.channel.send(embed=EmbedStatics.generate_end_embed(), view=ShareView(self, ctx.channel.id))
await ctx.channel.send(
embed=EmbedStatics.generate_end_embed(),
view=ShareView(self, ctx.channel.id),
)
# Close all conversation threads for the user
# If at conversation limit then fetch the owner and close the thread for them
@ -1289,6 +1294,7 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
from_other_action=from_other_action,
)
class ShareView(discord.ui.View):
def __init__(
self,
@ -1300,7 +1306,6 @@ class ShareView(discord.ui.View):
self.conversation_id = conversation_id
self.add_item(ShareButton(converser_cog, conversation_id))
async def on_timeout(self):
# Remove the button from the view/message
self.clear_items()
@ -1319,15 +1324,31 @@ class ShareButton(discord.ui.Button["ShareView"]):
async def callback(self, interaction: discord.Interaction):
# Get the user
try:
id = await self.converser_cog.sharegpt_service.format_and_share(self.converser_cog.full_conversation_history[self.conversation_id], self.converser_cog.bot.user.default_avatar.url if not self.converser_cog.bot.user.avatar else self.converser_cog.bot.user.avatar.url)
id = await self.converser_cog.sharegpt_service.format_and_share(
self.converser_cog.full_conversation_history[self.conversation_id],
self.converser_cog.bot.user.default_avatar.url
if not self.converser_cog.bot.user.avatar
else self.converser_cog.bot.user.avatar.url,
)
url = f"https://shareg.pt/{id}"
await interaction.response.send_message(embed=EmbedStatics.get_conversation_shared_embed(url))
await interaction.response.send_message(
embed=EmbedStatics.get_conversation_shared_embed(url)
)
except ValueError as e:
traceback.print_exc()
await interaction.response.send_message(embed=EmbedStatics.get_conversation_share_failed_embed("The ShareGPT API returned an error: "+str(e)), ephemeral=True, delete_after=15)
await interaction.response.send_message(
embed=EmbedStatics.get_conversation_share_failed_embed(
"The ShareGPT API returned an error: " + str(e)
),
ephemeral=True,
delete_after=15,
)
return
except Exception as e:
traceback.print_exc()
await interaction.response.send_message(embed=EmbedStatics.get_conversation_share_failed_embed(str(e)), ephemeral=True,
delete_after=15)
await interaction.response.send_message(
embed=EmbedStatics.get_conversation_share_failed_embed(str(e)),
ephemeral=True,
delete_after=15,
)
return

@ -229,20 +229,16 @@ class EmbedStatics:
color=discord.Color.blurple(),
)
# thumbnail of https://i.imgur.com/VLJ32x7.png
embed.set_thumbnail(
url="https://i.imgur.com/8OIZc1A.png"
)
embed.set_thumbnail(url="https://i.imgur.com/8OIZc1A.png")
return embed
@staticmethod
def get_conversation_share_failed_embed(message):
embed = discord.Embed(
title="Conversation Sharing",
description=f"Conversation sharing failed: "+message,
description=f"Conversation sharing failed: " + message,
color=discord.Color.red(),
)
# thumbnail of https://i.imgur.com/VLJ32x7.png
embed.set_thumbnail(
url="https://i.imgur.com/VLJ32x7.png"
)
embed.set_thumbnail(url="https://i.imgur.com/VLJ32x7.png")
return embed

@ -69,8 +69,7 @@ class PineconeService:
def get_all_conversation_items(self, conversation_id: int):
response = self.index.query(
vector=[0] * 1536,
top_k=1000, filter={"conversation_id": conversation_id}
vector=[0] * 1536, top_k=1000, filter={"conversation_id": conversation_id}
)
phrases = [match["id"] for match in response["matches"]]

@ -7,7 +7,9 @@ class ShareGPTService:
def __init__(self):
self.API_URL = "https://sharegpt.com/api/conversations"
def format_conversation(self, conversation_history, avatar_url="https://i.imgur.com/SpuAF0v.png"):
def format_conversation(
self, conversation_history, avatar_url="https://i.imgur.com/SpuAF0v.png"
):
# The format is { 'avatarUrl' : <url>, 'items': [ { 'from': 'human', 'text': <text> }, { 'from': 'bot', 'text': <text> } ] } "
# The conversation history is not in this format, its just in simple alternating human and bot conversation snippets
conversation = {"avatarUrl": avatar_url, "items": []}
@ -32,12 +34,13 @@ class ShareGPTService:
headers = {"Content-Type": "application/json"}
async with aiohttp.ClientSession() as session:
async with session.post(self.API_URL, data=conversation, headers=headers) as response:
async with session.post(
self.API_URL, data=conversation, headers=headers
) as response:
if response.status == 200:
response_json = await response.json()
return response_json['id']
return response_json["id"]
else:
raise ValueError(f"ShareGPT returned an invalid response: {await response.text()}")
raise ValueError(
f"ShareGPT returned an invalid response: {await response.text()}"
)

@ -18,6 +18,7 @@ from services.moderations_service import Moderation
BOT_NAME = EnvService.get_custom_bot_name()
PRE_MODERATE = EnvService.get_premoderate()
class TextService:
def __init__(self):
pass
@ -67,7 +68,7 @@ class TextService:
from_action (bool, optional): If the function is being called from a message action. Defaults to False.
"""
new_prompt, _new_prompt_clean = (
prompt #+ "\n" + BOT_NAME
prompt # + "\n" + BOT_NAME
if not from_ask_command and not from_edit_command and not redo_request
else prompt
), prompt
@ -233,7 +234,6 @@ class TextService:
"give me one moment!"
)
await converser_cog.summarize_conversation(ctx, new_prompt)
# Check again if the prompt is about to go past the token limit
@ -341,16 +341,13 @@ class TextService:
conversation_id = ctx.channel.id
# A cleaner version for the convo history
response_text_clean = (
str(response_text)
)
response_text_clean = str(response_text)
# Create an embedding and timestamp for the prompt
response_text = (
"\n" + BOT_NAME + str(response_text) + "<|endofstatement|>\n"
)
# response_text = response_text.encode("ascii", "ignore").decode()
response_text = unidecode.unidecode(response_text)

Loading…
Cancel
Save