ausboss / PygDiscordBot

Discord bot that uses KoboldAI. Supports tavern cards and json files.
62 stars 27 forks source link

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

Open TheFairyMan opened 1 year ago

TheFairyMan commented 1 year ago

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.

ausboss commented 1 year ago

I do want to revisit and add some stuff like that. At this time I have been doing some other related AI projects and I will bring back the things I learned to this project.

TheFairyMan commented 1 year ago

Ah, nice, that would be cool. Also two little extra addition I would ask if it's possible is to allow the bot to monitor multiple channels and one for being able to tell it to send a preemptive message in one of them.

ausboss commented 1 year ago

You can list multiple channels separated by commas in the .env file like 12353213,145632565,2466322554 and it should keep the chat logs and conversation history separate. I've played around with the preemptive message before but ended up removing it because I'm constantly restarting it and it got annoying. I could probably add it back

TheFairyMan commented 1 year ago

Oh, I did it wrong them, I added a space after the comma and that gave me errors, thanks for letting me know.

y preemptive message I meant something like, you pass a command through the condole itself and tell the bot to go say hi or do something in a channel, not a startup message, just so it calls attention of people.

ausboss commented 1 year ago

Oh I could probably add a slash command for that. I'll play around with that idea and see how it goes

TheFairyMan commented 1 year ago

Ah, thank you, also, I noticed a new issue, the character information doesn't gets passed fully every time as the chat history starts to pile up, so the character jsut loses itself.

Also, do you have a set parameter for Temperature, top p, top k and typical p or does it use the one set on the kobold server running? Because it seemed like character was being too random despite being on pygmalion 13B or 7B and would end up just repeating itself forever, then when it stopped parsing char info into the prompt for some reason it became even worse.

Edit: Seems like it only stops passing the character sheet when an error happens, next time it happens I'll copy it and put here.

Edit 2: ah, it only happens when somebody sends an image:

asyncio.run(runner())
  File "C:\Users\TheFairyMan\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Users\TheFairyMan\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 636, in run_until_complete
    self.run_forever()
  File "C:\Users\TheFairyMan\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 321, in run_forever
    super().run_forever()
  File "C:\Users\TheFairyMan\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 603, in run_forever
    self._run_once()
  File "C:\Users\TheFairyMan\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 1909, in _run_once
    handle._run()
  File "C:\Users\TheFairyMan\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\client.py", line 441, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\discordbot.py", line 164, in on_ready
    new_name = input('Too many users have this username, Enter a new name(tip: üse án àccent lèttèr ): ')

Error for not passing the entire chracter sheet stopped appearing, also I'm guessing u have some presets for the temp settings, since no matter what I change bot still breaking a lot and repeating so much, would it be possible to set to sue the default one that the API is using instead of sending a new parameter?

TheFairyMan commented 1 year ago

Another thing I wonder, do you have something that trims the messages? because I see on the console log that way more tokens were generated, but the message seems to cut out on the first full stop(.) and character never completes their response if it takes multiple lines to do so.

ausboss commented 1 year ago

I did throw together some crude slash commands that let you change those model parameters from within discord . try pressing "/" and see if they pop up. Otherwise I just recommend opening up the pygbot.py file and manually tweaking them in there. Sorry that's the best I got for now but I will improve that soon. I am also going to work on a better response parsing message that will use a more "dynamic" stop token system. The bots dont just stop after writing their message so it can get a little tricky on finding a way to only get the relevant parts. I need to fully understand what world info does and then I would be happy to add it. I'm just not exactly sure how they even achieved that in Kobold. I need to talk to Henky.

TheFairyMan commented 1 year ago

Thank you, will try changing it. As for the "/" commands, it gives me an error for both set and get commands, while I was trying to get or set the temperature, but same errors also happens for for any other parameters that I try setting or getting, thus I'm not sure if the parameter changes were applied correctly when changed in the pybot.py, could also be because of the message parsing and being cut that it seems different, sadly the console doesn't display the response nor if the temp parameters were changed when the request arrived.. Also, maybe trying to do something similar to what TavernAI or KoboldAI (In chat mode) does, where it only looks to see if the bot has started trying to impersonate the user, then it cuts it off there, thou I'm not sure how that is done, u would need to ask either in TavernAI discord or the Kobold discord. Also, is the parsing code easy to find? I could check and give it a try. Error for set:

  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\cogs\pygbot.py", line 259, in koboldput
    await interaction.response.send_message(embed=embedder(f"Error: {e}"), delete_after=12)
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\interactions.py", line 778, in send_message
    await adapter.create_interaction_response(
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\webhook\async_.py", line 219, in request
    raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

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

Traceback (most recent call last):
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\app_commands\tree.py", line 1248, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\app_commands\commands.py", line 867, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\app_commands\commands.py", line 860, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'koboldput' raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

Error for Get:

  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\cogs\pygbot.py", line 250, in koboldget
    await interaction.response.send_message(embed=embedder(f"Error: {e}"), delete_after=12)
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\interactions.py", line 778, in send_message
    await adapter.create_interaction_response(
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\webhook\async_.py", line 219, in request
    raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

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

Traceback (most recent call last):
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\app_commands\tree.py", line 1248, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\app_commands\commands.py", line 867, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\app_commands\commands.py", line 860, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'koboldget' raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

the /followup also gives an error:

  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\interactions.py", line 638, in defer
    await adapter.create_interaction_response(
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\webhook\async_.py", line 221, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In name: Username cannot contain "discord"

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

Traceback (most recent call last):
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\app_commands\tree.py", line 1248, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\app_commands\commands.py", line 867, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
  File "C:\Users\TheFairyMan\OneDrive\Documentos\Bots-Discord\PygDiscordBot\venv\lib\site-packages\discord\app_commands\commands.py", line 860, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'followup' raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In name: Username cannot contain "discord"

EDIT: Forgot to say which parameters I set, I tried setting the Ouroboros preset, since it normally comes out with interesting responses.:

model_config = {
    "use_story": False,
    "use_authors_note": False,
    "use_world_info": False,
    "use_memory": False,
    "max_context_length": 2400,
    "max_length": 180,
    "rep_pen": 1.05,
    "rep_pen_range": 404,
    "rep_pen_slope": 0.8,
    "temperature": 1.07,
    "tfs": 0.93,
    "top_p": 1.0,
    "top_p": 1.0,
    "top_a": 0.0,
    "typical": 1,
    "sampler_order": [0, 5, 3, 2, 1, 4, 6]
}