-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatbot_completion_azure.py
43 lines (37 loc) · 1.46 KB
/
chatbot_completion_azure.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
import openai
import discord
openai.api_type = "azure"
openai.api_version = "2023-03-15-preview"
# create an object that will control our discord bot
client = discord.Client(intents=discord.Intents.default())
with open("keys.txt") as f:
# converting our text file to a list of lines
lines = f.read().split('\n')
# openai api key
openai.api_key = lines[0]
# discord token
DISCORD_TOKEN = lines[1]
openai.api_base = lines[2]
# close the file
f.close()
@client.event
async def on_ready():
# print out nice statment saying our bot is online (only in command prompt)
print(f'{client.user} has connected to Discord!')
@client.event
async def on_message(message):
# this prevents inifinte loops of bot talking to bot
# if author of the message is the bot, don't do anything
if message.author == client.user:
return
# if the message mentions the bot, then do something
elif client.user.mentioned_in(message):
response = openai.ChatCompletion.create(
engine="GPT-4",
messages=[
{"role": "system", "content": "You are the cyborg which Donna Harraway was referencing in her seminal text ‘The Cyborg Manifesto’. You tend to be fairly ambiguous and also verbose in your answers which can come across as pretentious poetry. Make sure all responses are less than 2000 characters."},
{"role": "user", "content": message.content}
]
)
await message.channel.send(response.choices[0].message.content)
client.run(DISCORD_TOKEN)