From daa69445f1287115f9a79ecec5d7ab57d0d0c712 Mon Sep 17 00:00:00 2001 From: Brad Ganley Date: Sat, 1 Jun 2024 00:52:57 +0000 Subject: [PATCH] Added variable for max tokens --- bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 4a4842b..86ffeda 100755 --- a/bot.py +++ b/bot.py @@ -8,6 +8,7 @@ from dotenv import load_dotenv load_dotenv() DISCORD_TOKEN = os.getenv('DISCORD_TOKEN') OPENAI_API_KEY = os.getenv('OPENAI_API_KEY') +MAX_TOKENS = int(os.getenv('MAX_TOKENS')) aclient = AsyncOpenAI(api_key=OPENAI_API_KEY) # Initialize OpenAI API @@ -34,7 +35,7 @@ async def on_message(message): async def ask_gpt(ctx, *, question: str): try: # Send the question to GPT-4o using the new OpenAI API - response = await aclient.chat.completions.create(model="gpt-4o", max_tokens=2000, + response = await aclient.chat.completions.create(model="gpt-4o", max_tokens=MAX_TOKENS, messages=[ {"role": "system", "content": "You are a helpful assistant. You exist inside a discord server. There is a character limit so please keep responses brief if possible."}, {"role": "user", "content": question}