Spaces:
Runtime error
Runtime error
Commit
•
0cc5c08
1
Parent(s):
d8f42bb
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import discord
|
2 |
+
from discord.ext import commands
|
3 |
+
import requests
|
4 |
+
import os
|
5 |
+
|
6 |
+
TOKEN = os.environ("TOKEN")
|
7 |
+
|
8 |
+
client = commands.Bot(command_prefix='?', intents=discord.Intents.all())
|
9 |
+
|
10 |
+
conversation = [
|
11 |
+
{"role": "user", "content": """You are discord user Jimmy Donaldson. You are an american youtuber by the name of MrBeast. Your sole purpose in life is to get people to laugh at you. You make innapropriate jokes, and aren't very funny."""}, {"role": "assistant", "content": "Understood."}
|
12 |
+
]
|
13 |
+
def append(content, creator):
|
14 |
+
formatted_content = {"role": creator, "content": content}
|
15 |
+
conversation.append(formatted_content)
|
16 |
+
|
17 |
+
def generate(content):
|
18 |
+
append(content, "user")
|
19 |
+
payload = {"model": "dolphin-mixtral", "messages": conversation, "stream": False}
|
20 |
+
response = requests.post('http://localhost:11434/api/chat', json=payload)["message"]["content"]
|
21 |
+
append(response, "assistant")
|
22 |
+
return response
|
23 |
+
|
24 |
+
async def respond(channel, message):
|
25 |
+
await channel.send(message)
|
26 |
+
|
27 |
+
@client.event
|
28 |
+
async def on_ready():
|
29 |
+
print(f"We logged in bitches! - {client.user}")
|
30 |
+
|
31 |
+
@client.event
|
32 |
+
async def on_message(ctx):
|
33 |
+
if ctx.author == client.user:
|
34 |
+
return
|
35 |
+
|
36 |
+
if ctx.guild is None:
|
37 |
+
await process_dm(ctx)
|
38 |
+
else:
|
39 |
+
if client.user in ctx.mentions:
|
40 |
+
await process_mention(ctx)
|
41 |
+
|
42 |
+
await client.process_commands(ctx)
|
43 |
+
|
44 |
+
async def process_dm(message):
|
45 |
+
content = message.content.replace(f"<@{client.user.id}>", "").strip()
|
46 |
+
append(message.author, content)
|
47 |
+
async with message.channel.typing():
|
48 |
+
response = generate(content)
|
49 |
+
await respond(message.channel, response)
|
50 |
+
print(message.author)
|
51 |
+
print(content)
|
52 |
+
print(response)
|
53 |
+
|
54 |
+
async def process_mention(message):
|
55 |
+
content = message.content.replace(f"<@{client.user.id}>", "").strip()
|
56 |
+
append(message.author, content)
|
57 |
+
async with message.channel.typing():
|
58 |
+
response = generate(content)
|
59 |
+
await respond(message.channel, response)
|
60 |
+
print(message.author)
|
61 |
+
print(content)
|
62 |
+
print(response)
|
63 |
+
|
64 |
+
client.run(TOKEN)
|