-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
62 lines (52 loc) · 1.45 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import discord
import openai
token = os.environ['SECRET_KEY']
openai.api_key = os.getenv("OPENAI_API_KEY")
# file = input("Enter 1, 2, or 3 for loading the chat:\n ")
file = "2"
match(file):
case "1":
file = "chat1.txt"
case "2":
file = "chat2.txt"
case "3":
file = "chat3.txt"
case _:
print("Invalid choice.")
exit()
with open(file, "r") as f:
chat = f.read()
class MyClient(discord.Client):
async def on_ready(self):
print(f'Logged on as {self.user}!')
async def on_message(self, message):
global chat
try:
chat += f"{message.author}: {message.content}\n"
print(f'Message from {message.author}: {message.content}')
if self.user != message.author:
response = openai.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{
"role": "system",
"content": f"{chat}\nRanitGPT:"
}, {
"role": "user",
"content": message.content
}],
temperature=1,
max_tokens=500,
top_p=1,
frequency_penalty=0,
presence_penalty=0)
channel = message.channel
messageToSend = response.choices[0].message.content
await channel.send(messageToSend)
except Exception as e:
print(e)
chat = ""
intents = discord.Intents.default()
intents.message_content = True
client = MyClient(intents=intents)
client.run(token)