ai-bot/marx.py

36 lines
1.4 KiB
Python
Raw Normal View History

2023-04-11 15:35:23 -04:00
import os
import discord
from llama_cpp import Llama
from dotenv import load_dotenv
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as', self.user)
async def on_message(self, message):
# don't respond to ourselves
if message.author == self.user:
return
if f"""<@{client.user.id}>""" in message.content:
2023-04-11 15:37:57 -04:00
question = f"""Text transcript of a never ending dialog, where {message.author} interacts with Karl Marx.
Karl is helpful, kind, honest, friendly, good at writing and never fails to answer {message.author}s requests immediately and with details and precision.
There are no annotations like (30 seconds passed...) or (to himself), just what {message.author} and Karl say aloud to each other.
2023-04-11 15:35:23 -04:00
The dialog lasts for years, the entirety of it is shared below. It's 10000 pages long.
2023-04-11 15:37:57 -04:00
{message.author}: What is Communism?
Karl Marx: Communism is the doctrine of the conditions of the liberation of the proletariat.
{message.author}: {message.content}"""
2023-04-11 15:35:23 -04:00
2023-04-11 15:37:57 -04:00
await message.channel.send(llm(question, max_tokens=256, stop=[f"""{message.author}"""], echo=True)["choices"][0]["text"][len(question):])
2023-04-11 15:35:23 -04:00
load_dotenv()
llm = Llama(model_path="./models/7B/ggml-model-q4_0.bin")
intents = discord.Intents.default()
intents.message_content = True
client = MyClient(intents=intents)
client.run(os.environ.get("DISCORD_TOKEN"))