Skip to content

jediknight813/llama-cpp-discord-bot

Repository files navigation

llama-cpp-discord-bot

This Discord bot, which is written in Python and uses the Discord.py library, leverages the llama-cpp-python bindings to generate responses. It offers several commands for controlling the bot and interacting with the models it has access to.

llama-cpp-python: https://github.com/abetlen/llama-cpp-python

Discord.py: https://github.com/Rapptz/discord.py

basic chatbot mode.

@{botname} question 

Screen Shot 2023-04-24 at 4 34 42 PM

List All Models Command.

You can list every model in your models folder with the following command:

/list_models 

This will provide you with a list of all the models available to the bot.

Screen Shot 2023-04-24 at 4 37 46 PM

Switch Model Command.

To switch to a different model, simply specify the name of the model you want to switch to:

/change_model {model_name} 

This will change the bot's active model.

Screen Shot 2023-04-24 at 4 38 16 PM

Shutdown bot Command.

To shut down the bot, use the following command:

/shutdown 

This will terminate the bot.

Screen Shot 2023-04-24 at 5 07 20 PM

List All Bot Personalities Command.

You can list every personality in your bot_personality folder with the following command:

/list_personalities

This will provide you with a list of all the personalities available to the bot. Screen Shot 2023-05-23 at 4 05 43 PM

Switch Bot Personality Command.

To switch to a different Personality, simply specify the name of the Personality you want to switch to:

/change_bot_personality {personality_name} 

This will change the bot's active personality.

Screen Shot 2023-05-23 at 4 15 18 PM

Quick Setup

To get started quickly, follow these steps:

  1. Clone this repository:
git clone https://github.com/jediknight813/llama-cpp-discord-bot.git 
  1. Install the dependencies:
pip install -r requirements.txt
  1. Add a llama.cpp compatible model in the models folder.

Screen Shot 2023-04-24 at 5 23 43 PM

  1. Rename the .env.example file to .env.

Screen Shot 2023-05-23 at 4 11 17 PM

  1. Set your discord bot token and model path in the .env file.
discord_bot_token = '1234'
llm_model_path = './models/ggml-vicuna-7b-1.1-q4_0.bin'
  1. Run the bot:
python scripts/main.py

Using Docker

Make sure you have docker desktop installed and running.

  1. Clone this repository:
git clone https://github.com/jediknight813/llama-cpp-discord-bot.git 
  1. Rename the .env.example file to .env.

Screen Shot 2023-05-23 at 4 11 17 PM

  1. Add a llama.cpp compatible model in the models folder.

Screen Shot 2023-04-24 at 5 23 43 PM

  1. Set your discord bot token and model path in the .env file.
discord_bot_token = '1234'
llm_model_path = './models/ggml-vicuna-7b-1.1-q4_0.bin'
  1. Build the docker image
docker build -t llama-cpp-discord-bot:latest . 
  1. Run it
docker run llama-cpp-discord-bot:latest

Bot Customization

I've tried to make it as easy as possible to make a new bot personality.

First create a new json file with your bots name.

Screen Shot 2023-05-23 at 4 24 14 PM

Then paste this in the file:

{
    "bot_personality": "",
    "bot_name": "",
    "bot_image": "./images/"
}

Bot Personality

Change this to whatever you like, keep in mind that the longer this is the more time it will take for the bot to respond.

bot_personality = 'you are a chatbot named llama-bot, and you never fail to answer the users questions with experience and precision.' 

Bot Profile Picture

Add the image you want for the bot in the images folder and add it to your bots json file.

bot_image = './images/default.png' 

Bot Name

Change this to whatever you like.

bot_name = 'llama-bot'

Bot Settings

bot permissions

If you don't want users without permissions running the bot commands (change model, list_models, shutdown) add the role name to the bot_allowed_command_roles in the settings.py file.

bot_allowed_command_roles = ['admin']

If you don't want the bot to reply in every channel on the server, add the channel name to the bot_allowed_channels in the settings.py file.

bot_allowed_channels = ['general']

About

A simple discord chatbot that uses llama-cpp-python.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages