2023-04-11 15:41:34 -04:00
|
|
|
|
#!/bin/python3.10
|
2023-04-11 17:44:26 -04:00
|
|
|
|
import sys
|
2023-04-11 15:35:23 -04:00
|
|
|
|
import os
|
2023-04-11 17:44:26 -04:00
|
|
|
|
import random
|
|
|
|
|
|
2023-04-11 15:35:23 -04:00
|
|
|
|
import discord
|
2023-04-11 17:44:26 -04:00
|
|
|
|
from discord.ext import commands
|
2023-04-11 15:35:23 -04:00
|
|
|
|
from llama_cpp import Llama
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
2023-04-11 17:44:26 -04:00
|
|
|
|
description = """
|
|
|
|
|
An example bot to showcase the discord.ext.commands extension module.
|
|
|
|
|
There are a number of utility commands being showcased here.
|
|
|
|
|
"""
|
2023-04-11 15:35:23 -04:00
|
|
|
|
|
2023-04-11 17:44:26 -04:00
|
|
|
|
load_dotenv()
|
|
|
|
|
llm = Llama(model_path="./models/gpt4all-7B/gpt4all-lora-quantized.bin")
|
2023-04-11 15:35:23 -04:00
|
|
|
|
|
2023-04-11 17:44:26 -04:00
|
|
|
|
bot = commands.Bot(
|
|
|
|
|
command_prefix=commands.when_mentioned_or("!"),
|
|
|
|
|
description=description,
|
|
|
|
|
intents=discord.Intents.all(),
|
|
|
|
|
)
|
2023-04-11 15:35:23 -04:00
|
|
|
|
|
|
|
|
|
|
2023-04-11 17:44:26 -04:00
|
|
|
|
@bot.event
|
|
|
|
|
async def on_ready():
|
|
|
|
|
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
|
2023-04-11 15:35:23 -04:00
|
|
|
|
|
|
|
|
|
|
2023-04-11 17:44:26 -04:00
|
|
|
|
@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
|
2023-04-11 15:35:23 -04:00
|
|
|
|
|
2023-04-11 17:44:26 -04:00
|
|
|
|
if f"""<@{bot.user.id}>""" in message.content:
|
|
|
|
|
async with message.channel.typing():
|
2023-09-24 20:22:49 -04:00
|
|
|
|
question = f"""Text transcript of a never ending dialog, where {message.author} interacts with Karl AI.
|
2023-04-11 17:44:26 -04:00
|
|
|
|
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.
|
|
|
|
|
The dialog lasts for years, the entirety of it is shared below. It's 10000 pages long.
|
2023-04-11 15:35:23 -04:00
|
|
|
|
|
2023-04-11 17:44:26 -04:00
|
|
|
|
{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(msg)
|
|
|
|
|
|
|
|
|
|
bot.run(os.environ.get("DISCORD_TOKEN"))
|