Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 907140a

Browse files
committed
Feat: Increase heartbeat_timeout and add gpt_model user input to gpt_general_question command
1 parent 0ab6c8b commit 907140a

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

  • projects/Chat-GPT-Discord-Bot

projects/Chat-GPT-Discord-Bot/main.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
class MyClient(discord.Client):
4343
def __init__(self, *, intents: discord.Intents):
44-
super().__init__(heartbeat_timeout=90, intents=intents) # heartbeat_timeout=90 prevents the bot disconnecting from discord when running the dalle commands
44+
super().__init__(heartbeat_timeout=120, intents=intents) # heartbeat_timeout prevents the bot disconnecting from discord when running the dalle commands
4545
# A CommandTree is a special type that holds all the application command
4646
# state required to make it work. This is a separate class because it
4747
# allows all the extra states to be opt-in.
@@ -432,7 +432,8 @@ async def send(interaction: discord.Interaction, text: str): # noqa: F811
432432
@client.tree.command(name="gpt_general_question", description="For all your questions")
433433
@app_commands.rename(text="prompt")
434434
@app_commands.describe(text="What do you want to ask chatGPT?")
435-
async def send(interaction: discord.Interaction, text: str): # noqa: F811
435+
@app_commands.describe(gpt_model="Possible options = gpt-4 or gpt-3.5 (gpt-3.5-turbo-16k abbreviated)")
436+
async def send(interaction: discord.Interaction, text: str, gpt_model: str,): # noqa: F811
436437
try:
437438
await interaction.response.defer(
438439
ephemeral=False
@@ -445,12 +446,24 @@ async def send(interaction: discord.Interaction, text: str): # noqa: F811
445446
return
446447
else:
447448
gpt_prompt = text
449+
450+
if gpt_model.lower() not in ("gpt-4", "gpt-3.5"):
451+
await interaction.followup.send(
452+
"Invalid GPT model. Must be either gpt-4 or gpt-3.5."
453+
)
454+
return
455+
else:
456+
if gpt_model.lower() == "gpt-3.5":
457+
gpt_model = "gpt-3.5-turbo-16k"
458+
else:
459+
gpt_model = gpt_model.lower()
460+
448461

449462
# It is best to use discord embeds for gpt commands as discord embed descriptions allow for 4096 characters instead of 2000 characters for normal messages
450463
embed = discord.Embed(
451464
title=f'General Question - "{text}"',
452465
description=gpt(
453-
"gpt-3.5-turbo-16k",
466+
gpt_model,
454467
gpt_prompt,
455468
data["system_content"][0]["general_questions"],
456469
0.7,

0 commit comments

Comments
 (0)