Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,35 @@ async def on_ready():
max_tokens="How many tokens the model should output at max for each message."
)
async def chat_command(
int: discord.Interaction,
interaction: discord.Interaction,
message: str,
model: AVAILABLE_MODELS = DEFAULT_MODEL,
temperature: Optional[float] = 1.0,
max_tokens: Optional[int] = 512,
):
try:
# only support creating thread in text channel
if not isinstance(int.channel, discord.TextChannel):
if not isinstance(interaction.channel, discord.TextChannel):
return

# block servers not in allow list
if should_block(guild=int.guild):
if should_block(guild=interaction.guild):
return

user = int.user
user = interaction.user
logger.info(f"Chat command by {user} {message[:20]}")

# Check for valid temperature
if temperature is not None and (temperature < 0 or temperature > 1):
await int.response.send_message(
await interaction.response.send_message(
f"You supplied an invalid temperature: {temperature}. Temperature must be between 0 and 1.",
ephemeral=True,
)
return

# Check for valid max_tokens
if max_tokens is not None and (max_tokens < 1 or max_tokens > 4096):
await int.response.send_message(
await interaction.response.send_message(
f"You supplied an invalid max_tokens: {max_tokens}. Max tokens must be between 1 and 4096.",
ephemeral=True,
)
Expand All @@ -113,14 +113,14 @@ async def chat_command(
# moderate the message
flagged_str, blocked_str = moderate_message(message=message, user=user)
await send_moderation_blocked_message(
guild=int.guild,
guild=interaction.guild,
user=user,
blocked_str=blocked_str,
message=message,
)
if len(blocked_str) > 0:
# message was blocked
await int.response.send_message(
await interaction.response.send_message(
f"Your prompt has been blocked by moderation.\n{message}",
ephemeral=True,
)
Expand All @@ -140,19 +140,19 @@ async def chat_command(
embed.color = discord.Color.yellow()
embed.title = "⚠️ This prompt was flagged by moderation."

await int.response.send_message(embed=embed)
response = await int.original_response()
await interaction.response.send_message(embed=embed)
response = await interaction.original_response()

await send_moderation_flagged_message(
guild=int.guild,
guild=interaction.guild,
user=user,
flagged_str=flagged_str,
message=message,
url=response.jump_url,
)
except Exception as e:
logger.exception(e)
await int.response.send_message(
await interaction.response.send_message(
f"Failed to start chat {str(e)}", ephemeral=True
)
return
Expand All @@ -179,7 +179,7 @@ async def chat_command(
)
except Exception as e:
logger.exception(e)
await int.response.send_message(
await interaction.response.send_message(
f"Failed to start chat {str(e)}", ephemeral=True
)

Expand Down