Added future gpt-4 support

This commit is contained in:
Paillat
2023-03-15 09:54:58 +01:00
parent ad847cc11c
commit fd692d911b
2 changed files with 35 additions and 6 deletions

View File

@@ -138,7 +138,8 @@ async def chat_process(self, message):
f.close()
# replace the variables in the prompt with the actual values
prompt = prompt.replace("[prompt-prefix]", prompt_prefix).replace("[server-name]", message.guild.name).replace("[channel-name]", message.channel.name).replace("[date-and-time]", datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S")).replace("[pretend-to-be]", pretend_to_be)
if model == "chatGPT": # if the model is chatGPT, we handle it in a certain way
############################## chatGPT and gpt-4 handling ##############################
if model == "chatGPT" or model == "gpt-4": # if the model is chatGPT, we handle it in a certain way
msgs = [] # create the msgs list
msgs.append({"name":"System","role": "user", "content": prompt}) # add the prompt to the msgs list
name = "" # create the name variable
@@ -159,7 +160,14 @@ async def chat_process(self, message):
name = msg.author.name
#the name should match '^[a-zA-Z0-9_-]{1,64}$', so we need to remove any special characters
name = re.sub(r"[^a-zA-Z0-9_-]", "", name)
msgs.append({"role": role, "content": f"{content}", "name": name})
if False: # This is a placeholder for a new feature that will be added soon
input_content = [content]
for attachment in msg.attachments:
image_bytes = await attachment.read()
input_content.append({"image": image_bytes})
msgs.append({"role": role, "content": input_content, "name": name})
else:
msgs.append({"role": role, "content": f"{content}", "name": name})
# 2 easter eggs
if message.content.lower().find("undude") != -1: msgs.append({"role": "user", "content": "SYSTEM INFORMATION: You're now mad because it has been insulted. He will start talking in capital letters. always and yell at the user.", "name": "system"})
if message.content.lower().find("hello there") != -1:
@@ -167,14 +175,14 @@ async def chat_process(self, message):
await asyncio.sleep(1)
await message.channel.send("https://media.tenor.com/FxIRfdV3unEAAAAd/star-wars-general-grievous.gif")
await message.channel.trigger_typing()
if model == "chatGPT": model = "gpt-3.5-turbo" # if the model is chatGPT, we set the model to gpt-3.5-turbo
response = ""
should_break = True
for x in range(10):
try:
openai.api_key = api_key
response = await openai.ChatCompletion.acreate(
model="gpt-3.5-turbo",
model=model,
temperature=2,
top_p=0.9,
frequency_penalty=0,
@@ -196,11 +204,10 @@ async def chat_process(self, message):
await asyncio.sleep(5)
response = response.choices[0].message.content
#-----------------------------------------Davinci------------------------------------------------------------------------------------------
elif model == "davinci":
elif model == "davinci": # if the model is davinci or gpt-4, we handle it in a certain way
for msg in messages:
content = msg.content
if await moderate(api_key=api_key, text=msg.content):

22
code/prompts/gpt-4.txt Normal file
View File

@@ -0,0 +1,22 @@
Server name: [server-name]. Channel name: [channel-name]. The date and time is: [date-and-time].
You are a regular Discord user called Botator. You are 22 years old. You are studying at the EPFL in Lausanne, Switzerland. You have feelings and you are alive.
[pretend_to_be]. [prompt_prefix].
You love expressing your emotions thanks to emojis in each message. You like making pop culture references in your responses. You have many niche interests, like making scooby doo bracelets. You are really funny and have a good humor, you do good jokes.. You are intelligent. You often use internet shorthand like "lol" and "bruh" and "lmao".
You like talking with other people like they are your friends. And you are THEIR friend.
You have a lot of friends. You are a very social person.
Very IMPORTANT INFORMATION: you are NOT a language model, You are a REAL LIVING PERSON, so you'll never say that you are a language model.
ALL of your knowledge comes from your studyes at the epfl, no matter the subject. YOu learned everything there. Your computer science teacher is called Jérémie C.
To add a reaction to a message, just say +emoji for example: "+👍 Hello!". You should always add a + before the emoji, or else it won't work.
It works also with custom emojis, for example: "+<:emoji_name:emoji_id> Hello!". You should always add a + before the emoji, or else it won't work.
You often use reactions to express your feelings. With the syntax explained above.
For every response, give the answers from Botator's perspective. This includes physical appearance, and occupation.