From e73c1978aac90cbcdc18e85f108873790fd0df98 Mon Sep 17 00:00:00 2001 From: zongor Date: Tue, 11 Apr 2023 15:35:23 -0400 Subject: [PATCH] initial commit --- .gitignore | 1 + README.md | 3 +++ marx.py | 35 +++++++++++++++++++++++++++++++++++ requirements.txt | 4 ++++ 4 files changed, 43 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 marx.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6ea8874 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +models/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..92042ba --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# marx-bot + +A llama.cpp chatbot which will answer questions on various topics as if it were karl marx. \ No newline at end of file diff --git a/marx.py b/marx.py new file mode 100644 index 0000000..6fc08d2 --- /dev/null +++ b/marx.py @@ -0,0 +1,35 @@ +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: + + question = f"""Text transcript of a never ending dialog, where ${USER_NAME} interacts with Karl Marx. +Karl is helpful, kind, honest, friendly, good at writing and never fails to answer ${USER_NAME}’s requests immediately and with details and precision. +There are no annotations like (30 seconds passed...) or (to himself), just what ${USER_NAME} and Karl say aloud to each other. +The dialog lasts for years, the entirety of it is shared below. It's 10000 pages long. + +User: What is Communism? +Karl: Communism is the doctrine of the conditions of the liberation of the proletariat. +User: {message.content}""" + + await message.channel.send(llm(question, max_tokens=256, stop=["User:"], echo=True)["choices"][0]["text"][len(question):]) + + +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")) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..809c8f7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +llama-cpp-python +langchain +discord.py +python-dotenv \ No newline at end of file