Coder Social home page Coder Social logo

ausboss / pygdiscordbot Goto Github PK

View Code? Open in Web Editor NEW
60.0 7.0 27.0 3.79 MB

Discord bot that uses KoboldAI. Supports tavern cards and json files.

Python 94.40% Shell 1.45% Batchfile 4.16%
artificial-intelligence chatbot discord discord-bot gpt-3 pygmalion roleplay python ai koboldai

pygdiscordbot's Introduction

update

apparently people still use this. I appreciate that so I will start improving the main repo again. I added a few changes.

  • added max tokens to env, for kobold the max is 512, so dont go over that or you will get an error

  • There is now stop token support. Update your .envs based on the new sample env. just list words that you dont want to see the bot say divided by ,

  • bot will now say your display name and not your username

  • i modified the endpoint and conversation history to use langchain and soon i will add oobabooga support. i just need to add a line to detect what api you put as the endpoint. (ADDED)

-more to come soon..

Original Info Card: Discord Tavern Style LLM Chatbot

This Discord bot utilizes LLMs and character cards for casual chatting. The bot supports JSON files and tavern cards, offering the option to automatically update the bot's image and name.

image

Instructions

  1. Clone the repository.
  2. Modify the variables in the sample.env file and save it as .env in the same folder.
  3. Run the setup.bat file.
  4. Run the run.bat file.
  5. Choose the character.

Choose

Please note that Discord only allows bots to be renamed twice per hour.

More Information

  • DISCORD_BOT_TOKEN: Obtain this token from the Discord Developer Portal. Guide for setting that up
  • ENDPOINT: I recommend using this

https://github.com/oobabooga/text-generation-webui#one-click-installers

after you install it you will want to run with the --api parameter, or select it in the webui. Then you can set the .env endpoint as http://127.0.0.1:5000/ assuming that you are running it locally.

Slash Commands

Currently, these commands are primarily useful for developers. If you don't see them, use the /sync command to force their appearance.

Command Name Slash Command More Info
Sync Commands /sync Forces the slash commands to appear immediately.
Reload Cog /reload <name> Reloads a specific cog instead of restarting everything.
Regenerate Last Message /regenerate Removes the last message and generates another one.

Tip for making the .env file

Enable file name extensions

Windows 11:

win11img

Windows 10:

win10img

Now you can easily rename it to .env

envgif

pygdiscordbot's People

Contributors

ausboss avatar n-galrion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pygdiscordbot's Issues

No obvious way to choose generation settings

Right now, I can't figure out how to alter generation settings, such as temperature, rept-penalty, tail-free sampling etc, and I also don't know how to change maximum generation length. Digging around, it seems that the option used to be in cogs/pygbot.py, but it doesn't seem to be in there now.

Tavern cards not being recognized

Having a issue where tavern cards arent be read. i may be doing something wrong but i dont know how to fix it. i managed to get it to read the folder once but i cant replicate it.

Cannot send empty message

I'm having some issues with trying to generate responses, more often than not I get an error like this. I first assumed it was due to my VRAM usage basically topping out. But switching to Pyg2.7B did not alleviate this issue in the slightest. Any idea how to solve this issue?

[2023-09-11 19:53:28] [ERROR   ] discord.client: Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\harry\Desktop\PygDiscordBot-main\venv\lib\site-packages\discord\client.py", line 441, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\harry\Desktop\PygDiscordBot-main\cogs\messagehandler.py", line 64, in on_message
    await message.channel.send(response)
  File "C:\Users\harry\Desktop\PygDiscordBot-main\venv\lib\site-packages\discord\abc.py", line 1561, in send
    data = await state.http.send_message(channel.id, params=params)
  File "C:\Users\harry\Desktop\PygDiscordBot-main\venv\lib\site-packages\discord\http.py", line 745, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50006): Cannot send an empty message```

PR

i tried to make a PR but i got an error
Pull request creation failed. Validation failed: must be a collaborator

        if "https://giphy.com/gifs/" in message_content:
            # Extract the giphy GIF URL from the message content
            start_index = message_content.index("https://giphy.com/gifs/")
            end_index = message_content.find(" ", start_index)
            if end_index == -1:
                tenor_url = message_content[start_index:]
            else:
                tenor_url = message_content[start_index:end_index]
            # Split the URL on forward slashes
            parts = tenor_url.split("/")
            # Extract the relevant words from the URL
            words = parts[-1].split("-")[:-1]
            # Join the words into a sentence
            sentence = " ".join(words)
            message_content = f"{message_content} [{message.author.name} posts an animated {sentence} ]"
            message_content = message_content.replace(tenor_url, "")
            return message_content
 giphy_pattern = re.compile(r'https://giphy.com/gifs/[\w-]+')


        elif giphy_pattern.search(message.content):
            return True

i lost my formatting and explanation of the code that I typed out because of the permission error so here you go.

discord.client: Ignoring exception in on_message

[2023-08-01 01:45:02] [ERROR ] discord.client: Ignoring exception in on_message Traceback (most recent call last): File "D:\PygDiscordBot-main\venv\lib\site-packages\discord\client.py", line 441, in _run_event await coro(*args, **kwargs) File "D:\PygDiscordBot-main\cogs\messagehandler.py", line 59, in on_message response = await self.bot.get_cog("chatbot").chat_command(message, message.clean_content) File "D:\PygDiscordBot-main\venv\lib\site-packages\discord\ext\commands\core.py", line 588, in __call__ return await self.callback(self.cog, context, *args, **kwargs) # type: ignore File "D:\PygDiscordBot-main\cogs\pygbot.py", line 243, in chat_command response = await self.chatbot.generate_response(message, message_content) File "D:\PygDiscordBot-main\cogs\pygbot.py", line 197, in generate_response response_text = conversation(input_dict) File "D:\PygDiscordBot-main\venv\lib\site-packages\langchain\chains\base.py", line 258, in __call__ raise e File "D:\PygDiscordBot-main\venv\lib\site-packages\langchain\chains\base.py", line 252, in __call__ self._call(inputs, run_manager=run_manager) File "D:\PygDiscordBot-main\venv\lib\site-packages\langchain\chains\llm.py", line 92, in _call response = self.generate([inputs], run_manager=run_manager) File "D:\PygDiscordBot-main\venv\lib\site-packages\langchain\chains\llm.py", line 102, in generate return self.llm.generate_prompt( File "D:\PygDiscordBot-main\venv\lib\site-packages\langchain\llms\base.py", line 451, in generate_prompt return self.generate(prompt_strings, stop=stop, callbacks=callbacks, **kwargs) File "D:\PygDiscordBot-main\venv\lib\site-packages\langchain\llms\base.py", line 582, in generate output = self._generate_helper( File "D:\PygDiscordBot-main\venv\lib\site-packages\langchain\llms\base.py", line 488, in _generate_helper raise e File "D:\PygDiscordBot-main\venv\lib\site-packages\langchain\llms\base.py", line 475, in _generate_helper self._generate( File "D:\PygDiscordBot-main\venv\lib\site-packages\langchain\llms\base.py", line 961, in _generate self._call(prompt, stop=stop, run_manager=run_manager, **kwargs) File "D:\PygDiscordBot-main\venv\lib\site-packages\langchain\llms\koboldai.py", line 179, in _call response.raise_for_status() File "D:\PygDiscordBot-main\venv\lib\site-packages\requests\models.py", line 1021, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 422 Client Error: UNPROCESSABLE ENTITY for url: http://localhost:5000/api/v1/generate

I have no idea how to deal with this.... Lol...? This happens every time I write something

ModuleNotFoundError: No module named 'discord'

I am giving up on this bot as it just will not work.

Traceback (most recent call last):
File "D:\AI\PygDiscordBot-main\discordbot.py", line 4, in
import discord
ModuleNotFoundError: No module named 'discord'
Press any key to continue . . .

Multi-user option?

Has an option to support a sort of group chat mode been considered where the bot reads the full context of the channel and interacts each x messages as if they are a chat user? or each x seconds assuming at least one new message is present?

Enhancement Request - Add Entity memory

Have you considered modifying your custom memory class to not only be a buffer window but add langchains entity memory for a combined memory class? It would allow for the bot to retain key details about each user it interacts with and pull that users details into context when replying to said user. This way it not only has the buffer lf the last n chats but always keeps key details. There are more and more models coming out with larger context windows that could support this and it would be useful in very active servers where the last n lines of chat may not be enough to keep a thread going.

Langchain Entity Memory Doc

/regenerate throws AttributeError: 'Bot' object has no attribute 'name'

Tested /regenerate, bot cleaned up its messages, then threw this error.

2023-04-08 03:14:25 ERROR    discord.app_commands.tree Ignoring exception in command 'regenerate'
Traceback (most recent call last):
  File "PygDiscordBot/venv/lib/python3.9/site-packages/discord/app_commands/commands.py", line 841, in _do_call
    return await self._callback(self.binding, interaction, **params)  # type: ignore
  File "PygDiscordBot/cogs/pygbot.py", line 196, in regenerate
    if lines[i].startswith(f"{self.bot.name}:"):
AttributeError: 'Bot' object has no attribute 'name'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "PygDiscordBot/venv/lib/python3.9/site-packages/discord/app_commands/tree.py", line 1248, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "PygDiscordBot/venv/lib/python3.9/site-packages/discord/app_commands/commands.py", line 867, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
  File "PygDiscordBot/venv/lib/python3.9/site-packages/discord/app_commands/commands.py", line 860, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'regenerate' raised an exception: AttributeError: 'Bot' object has no attribute 'name'

Setup.bat causes this error - Help?

user site = 1
safe_path = 0
import site = 1
is in build tree = 0
stdlib dir = 'C:\Program Files\Python310\Scripts\Lib'
sys._base_executable = 'C:\Python311\python.exe'
sys.base_prefix = 'C:\Program Files\Python310\Scripts'
sys.base_exec_prefix = 'C:\Program Files\Python310\Scripts'
sys.platlibdir = 'DLLs'
sys.executable = 'C:\Python311\python.exe'
sys.prefix = 'C:\Program Files\Python310\Scripts'
sys.exec_prefix = 'C:\Program Files\Python310\Scripts'
sys.path = [
'C:\Python311\python311.zip',
'C:\Program Files\Python310\Scripts\DLLs',
'C:\Program Files\Python310\Scripts\Lib',
'C:\Python311',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00004574 (most recent call first):

Press any key to continue . . .

Docker container

Hello! Is there any chance we could see a dockerized version of this? Would love to be able to run it on my nas alongside ooba.

ExtensionFailed: Extension 'cogs.pygbot' raised an error: KeyError: 'name'

Not sure what happened here. There is an error regarding the cogs.pygbot. Using your latest branch btw.
Here's the log in my terminal output:

(env) [muzz@nobara-laptop PygDiscordBot]$ python discordbot.py 
1. Chiharu Yamada
2. Rise Kujikawa
3. Neuro sama
Please select a character: 3
Update Bot name and pic? (y or n): n
[nltk_data] Downloading package punkt to /home/muzz/nltk_data...
[nltk_data]   Package punkt is already up-to-date!
ExtensionFailed: Extension 'cogs.pygbot' raised an error: KeyError: 'name'
2023-02-24 22:42:08 INFO     discord.client logging in using static token
2023-02-24 22:42:10 INFO     discord.gateway Shard ID None has connected to Gateway (Session ID: 51c88715f42f6c5a1ec5ee11c533084a).
Neuro sama#7837 has connected to Discord!
2023-02-24 22:42:12 ERROR    discord.client Ignoring exception in on_message
Traceback (most recent call last):
  File "/home/muzz/.conda/envs/env/lib/python3.9/site-packages/discord/client.py", line 409, in _run_event
    await coro(*args, **kwargs)
  File "/home/muzz/build2/PygDiscordBot/discordbot.py", line 148, in on_message
    response = await bot.get_cog("chatbot").chat_command(message, message.content, bot)
AttributeError: 'NoneType' object has no attribute 'chat_command'

Instruct mode?

Any way to change it to instruct mode as opposed to chat?
I feel like there should be a / command for it

ERROR: Response: <Response [404]>

I keep getting "ERROR: Response: <Response [404]>" whenever I send a message in the channel.
The bot detects and knows what I last sent and it also shows that it is typing, but it never sends anything.

I'm running the backend on Oobabooga and its all on a linux 20.04 LTS server. I've use the bot before on other machines and it has worked before with the same model. Not sure why it's acting up now.

I checked through the code, it looks like it's showing as an issue with the stop sequences, but I've even gone as far as completely removing all of them so I'm out of ideas.

Would it be possible to add a section for world info as well?

Wondering if apart from cards it would be possible to load JSON files with world info or Lore books so when they're mentioned it just adds their context, like it is in KooldAI, SillyTavern and such, since adding everything to the character would be too much.

Unable to run locally

When trying to run this with a local instance of KoboldAI it doesn't get past line 170: if response.status_code == 200:
It will send the message properly to KoboldAI but KoboldAI isn't able to respond until the user manually goes in and clicks the submit button.

unknown error

Downloading pytorch_model.bin:  82%|██████████████████████████      | 807M/990M [01:06<00:14, 12.7MB/s]

i set ENDPOINT="http://127.0.0.1:5001/"
but it still downloads a 1B model? I'm running llama 70b locally so why does it need to download another pt model?

it also gives

    bot.run(DISCORD_BOT_TOKEN)
...
client.py", line 704, in connect
    raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001DAC3EFE820>
Traceback (most recent call last):
...
\client.py", line 704, in connect
    raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: **Shard ID None is requesting privileged intents** that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001DAC3EFE820>
Traceback (most recent call last):
...
\base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')

the token looks like
DISCORD_BOT_TOKEN="aaaaaaaaaaaaaaaaaaaaaaaaaa.Aa##A#.AAaaaaaaaaaaaaaa_aa_aaaa_aaaaaaaaaaaaa"

Error: .env file not found

I edited the sample.env using Notepad++ by inserting the token as explained in the rentry, I grabbed the channel ID from discord using dev mode, I successfully added the bot to my server.

I'm running occ4m's 4bit fork of KoboldAI, I used the local link that I use to connect to in tavern. Did I miss something? Or does this not work with 4bit?

image

No Local GPU Docs

There is a link that is supposed to show me how to use this locally on my GPU, but it does not lead anywhere.

Error when using run.bat

When I open run.bat, this message pops up in the terminal:

Traceback (most recent call last):
File "C:\Users\Ralph\PygDiscordBot\discordbot.py", line 41, in <module>
bot.always_reply = True if ALWAYS_REPLY.lower() == "t" else False
AttributeError: 'NoneType' object has no attribute 'lower'
Press any key to continue . . .

Errors related to imagecaption and cilent.py and a ton of other stuff.

Upon running the bot via it's bat file the following errors appear:

there was an error with the endpoint
Failed to load extension imagecaption
ExtensionFailed: Extension 'cogs.imagecaption' raised an error: ModuleNotFoundError: No module named 'torch'

Furthermore, after running the bot starts and recieves a message i get the following error:

CharacterName:←[0m
[2023-07-28 03:25:31] [ERROR   ] discord.client: Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\venv\Lib\site-packages\discord\client.py", line 441, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\cogs\messagehandler.py", line 59, in on_message
    response = await self.bot.get_cog("chatbot").chat_command(message, message.clean_content)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\venv\Lib\site-packages\discord\ext\commands\core.py", line 588, in __call__
    return await self.callback(self.cog, context, *args, **kwargs)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\cogs\pygbot.py", line 243, in chat_command
    response = await self.chatbot.generate_response(message, message_content)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\cogs\pygbot.py", line 197, in generate_response
    response_text = conversation(input_dict)
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\venv\Lib\site-packages\langchain\chains\base.py", line 258, in __call__
    raise e
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\venv\Lib\site-packages\langchain\chains\base.py", line 252, in __call__
    self._call(inputs, run_manager=run_manager)
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\venv\Lib\site-packages\langchain\chains\llm.py", line 92, in _call
    response = self.generate([inputs], run_manager=run_manager)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\venv\Lib\site-packages\langchain\chains\llm.py", line 102, in generate
    return self.llm.generate_prompt(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\venv\Lib\site-packages\langchain\llms\base.py", line 412, in generate_prompt
    return self.generate(prompt_strings, stop=stop, callbacks=callbacks, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\venv\Lib\site-packages\langchain\llms\base.py", line 543, in generate
    output = self._generate_helper(
             ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\venv\Lib\site-packages\langchain\llms\base.py", line 449, in _generate_helper
    raise e
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\venv\Lib\site-packages\langchain\llms\base.py", line 436, in _generate_helper
    self._generate(
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\venv\Lib\site-packages\langchain\llms\base.py", line 922, in _generate
    self._call(prompt, stop=stop, run_manager=run_manager, **kwargs)
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\venv\Lib\site-packages\langchain\llms\koboldai.py", line 179, in _call
    response.raise_for_status()
  File "C:\Users\admin\Documents\GitHub\PygDiscordBot\venv\Lib\site-packages\requests\models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity for url: https://challenges-restricted-computational-delicious.trycloudflare.com/api/v1/generate

I deleted the venv multiple times and reinstalling it, as well as making a clean install by cloning the git the proper way, I also tried reinstalling by clearing the pip cache in the rare chance a file got corrupted and nothing worked. Absolutely clueless how I could fix this. Might be a issue outside of my end?

AttributeError: 'NoneType' object has no attribute 'split'

I encountered an error while using the Discord bot script (discordbot.py). The error message states: "AttributeError: 'NoneType' object has no attribute 'split'". This issue prevents the bot from functioning

if len(bot.endpoint.split("/api")) > 0:
^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'split'

Getting error when running run.sh

\run.sh: line 6: .env: No such file or directory
File "discordbot.py", line 45
while Path(f'{characters_folder}/{outfile_name}.json').exists():

Any fixes?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.