upgrade to use pycord
This commit is contained in:
parent
743ca6ba75
commit
d0930de760
49
marx.py
49
marx.py
|
@ -1,21 +1,42 @@
|
||||||
#!/bin/python3.10
|
#!/bin/python3.10
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
from llama_cpp import Llama
|
from llama_cpp import Llama
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
description = """
|
||||||
|
An example bot to showcase the discord.ext.commands extension module.
|
||||||
|
There are a number of utility commands being showcased here.
|
||||||
|
"""
|
||||||
|
|
||||||
class MyClient(discord.Client):
|
load_dotenv()
|
||||||
async def on_ready(self):
|
llm = Llama(model_path="./models/gpt4all-7B/gpt4all-lora-quantized.bin")
|
||||||
print('Logged on as', self.user)
|
|
||||||
|
|
||||||
async def on_message(self, message):
|
bot = commands.Bot(
|
||||||
# don't respond to ourselves
|
command_prefix=commands.when_mentioned_or("!"),
|
||||||
if message.author == self.user:
|
description=description,
|
||||||
|
intents=discord.Intents.all(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@bot.event
|
||||||
|
async def on_ready():
|
||||||
|
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
|
||||||
|
|
||||||
|
|
||||||
|
@bot.event
|
||||||
|
async def on_message(message: discord.Message):
|
||||||
|
msg = ""
|
||||||
|
# Make sure we won't be replying to ourselves.
|
||||||
|
if message.author.id == bot.user.id:
|
||||||
return
|
return
|
||||||
|
|
||||||
if f"""<@{client.user.id}>""" in message.content:
|
if f"""<@{bot.user.id}>""" in message.content:
|
||||||
|
async with message.channel.typing():
|
||||||
question = f"""Text transcript of a never ending dialog, where {message.author} interacts with Karl Marx.
|
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.
|
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.
|
There are no annotations like (30 seconds passed...) or (to himself), just what {message.author} and Karl say aloud to each other.
|
||||||
|
@ -24,13 +45,9 @@ The dialog lasts for years, the entirety of it is shared below. It's 10000 pages
|
||||||
{message.author}: What is Communism?
|
{message.author}: What is Communism?
|
||||||
Karl Marx: Communism is the doctrine of the conditions of the liberation of the proletariat.
|
Karl Marx: Communism is the doctrine of the conditions of the liberation of the proletariat.
|
||||||
{message.author}: {message.content}"""
|
{message.author}: {message.content}"""
|
||||||
|
msg = llm(question, max_tokens=256, stop=[f"""{message.author}"""], echo=True)[
|
||||||
|
"choices"][0]["text"][len(question):]
|
||||||
|
|
||||||
await message.channel.send(llm(question, max_tokens=256, stop=[f"""{message.author}"""], echo=True)["choices"][0]["text"][len(question):])
|
await message.channel.send(msg)
|
||||||
|
|
||||||
|
bot.run(os.environ.get("DISCORD_TOKEN"))
|
||||||
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"))
|
|
||||||
|
|
Loading…
Reference in New Issue