-
Notifications
You must be signed in to change notification settings - Fork 10
/
chat.py
69 lines (55 loc) · 2.12 KB
/
chat.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
63
64
65
66
67
68
69
import asyncio
from rwkvstic.rwkvMaster import RWKVMaster
async def runDiscordBot(model: RWKVMaster):
import discord
import os
client = discord.Client(intents=discord.Intents.all())
@client.event
async def on_ready():
print(f"Logged in as {client.user}")
@client.event
async def on_message(message: discord.Message):
# check if author is bot
if message.author.bot:
return
# check if message is a command
if message.content.startswith("!rwkv "):
mess = await message.channel.send("Loading...")
model.resetState()
model.loadContext(
newctx=f"\n\nQuestion: {message.content[6:]}\n\nExpert Long Detailed Response: ")
tex = ""
for i in range(10):
print(i)
curr = model.forward(number=10)[
"output"]
tex = tex + curr
print(curr)
if ("<|endoftext|>" in curr):
break
mess = await mess.edit(content=tex)
await asyncio.sleep(1)
await mess.edit(content=tex)
if message.content.startswith("!code"):
text = message.content[6:]
language = text.split(" ")[0]
comment = text.split(" ")[1:]
mess = await message.channel.send("Loading...")
model.resetState()
model.loadContext(
newctx=f"Q: Please write a {language} program that {comment}\n\nA:")
model.loadContext(
newctx=f"```Sure, here is a {language} program that {comment}:\n\n//{comment}\n")
tex = ""
for i in range(20):
print(i)
curr = model.forward(number=10)[
"output"]
tex = tex + curr
print(curr)
if ("<|endoftext|>" in curr):
break
mess = await mess.edit(content=tex)
await asyncio.sleep(1)
await mess.edit(content=tex)
await client.start(os.environ.get("TOKEN", input("Discord Token:")))