Coder Social home page Coder Social logo

discord-ai-bot's Introduction

Discord AI Bot

Discord bot to interact with Ollama and AUTOMATIC1111 Stable Diffusion as a chatbot

Stars

Discord chat with the bot

New Maintainer

This repository is no longer being developed on by me, mekb-turtle.

Set-up instructions

  1. Install Node.js (if you have a package manager, use that instead to install this)
    • Make sure to install at least v14 of Node.js
  2. Install Ollama (ditto)
  3. Pull (download) a model, e.g ollama pull orca or ollama pull llama2
  4. Start Ollama by running ollama serve
  5. Create a Discord bot
    • Under Application » Bot
      • Enable Message Content Intent
      • Enable Server Members Intent (for replacing user mentions with the username)
  6. Invite the bot to a server
    1. Go to Application » OAuth2 » URL Generator
    2. Enable bot
    3. Enable Send Messages, Read Messages/View Channels, and Read Message History
    4. Under Generated URL, click Copy and paste the URL in your browser
  7. Rename .env.example to .env and edit the .env file
    • You can get the token from Application » Bot » Token, never share this with anyone
    • Make sure to change the model if you aren't using orca
    • Ollama URL can be kept the same unless you have changed the port
    • You can use multiple Ollama servers at the same time by separating the URLs with commas
    • Set the channels to the channel ID, comma separated
      1. In Discord, go to User Settings » Advanced, and enable Developer Mode
      2. Right click on a channel you want to use, and click Copy Channel ID
    • You can edit the system message the bot uses, or disable it entirely
  8. Install the required dependencies with npm i
  9. Start the bot with npm start
  10. You can interact with the bot by @mentioning it with your message
  11. Install Stable Diffusion
  12. Run the script ./webui.sh --api --listen

Set-up instructions with Docker

  1. Install Docker
    • Should be atleast compatible with version 3 of compose (docker engine 1.13.0+)
  2. Repeat steps 2—7 from the other setup instructions
  3. Start the bot with make compose-up if you have Make installed
    • Otherwise, try docker compose -p discord-ai up instead
  4. You can interact with the bot by @mentioning it with your message

discord-ai-bot's People

Contributors

238samixd avatar drhino avatar johnsonjo4531 avatar mekb-turtle 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  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

discord-ai-bot's Issues

Open-webui support

Describe the feature
I would love to have the option to have this discord bot interact with open-webui (https://github.com/open-webui/open-webui) instead of ollama.

Why do you think this feature should be implemented?
Having the ability to utilize some of the features of open-webui via the discord bot would greatly increase it's use and utility in my core discord communities. Features such as web search, RAG, YouTube video summaries, etc.

Additional context
In my setup, I have ollama running as the backend, and open-webui as the front end. Below are some screenshots of the open-webui admin Panel and their options. I don't know how difficult this request will be, but I hope it can be implemented in some capacity.
open-webui ollama connections
open-webui documents
open-webui web search

Open-webui documents:
https://docs.openwebui.com/

Thank you for reading!

The bot won’t send messages when using WSL

Describe the bug
Everything works perfectly, but for some reason it does not send requests from discord channel when running ollama and discord-ai-bot from wsl

To Reproduce

  • run ollama serve in wsl
  • Verify that it correctly receives get requests when browsing to the right address
  • Run discord-ai-bot from wsl
  • Try to send message from discord channel
  • No request is made through the bot

Expected behavior
Using the same token and files when running not in WSL works flawlessly

Device

  • OS: Windows/WSL

Discord has a 2,000-character Limit per Message

It seems that Ollama will be hitting against Discord's message size limit fairly regularly. Could be worth looking into the feasibility of chunking responses over multiple messages.

[Shard #0] [DEBUG] #study-room3 - boneitis-dev: tell me a dirty joke.
[Shard #0] [DEBUG] Response: Why did the chicken cross the road? To prove to the world that chickens can be just as smart as pigs.
[Shard #0] [DEBUG] #study-room3 - boneitis-dev: tell me another, but much more NSFW.
[Shard #0] [DEBUG] Response: Once upon a time there was a little boy who <..snip..original message was about 2800 characters..>
[Shard #0] [ERROR] DiscordAPIError[50035]: Invalid Form Body
content[BASE_TYPE_MAX_LENGTH]: Must be 2000 or fewer in length.
at handleErrors (/home/llamabeast/discord-ai-bot/node_modules/@discordjs/rest/dist/index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (/home/llamabeast/discord-ai-bot/node_modules/@discordjs/rest/dist/index.js:1072:23)
at async SequentialHandler.queueRequest (/home/llamabeast/discord-ai-bot/node_modules/@discordjs/rest/dist /index.js:913:14)
at async _REST.request (/home/llamabeast/discord-ai-bot/node_modules/@discordjs/rest/dist/index.js:1218:22)
at async TextChannel.send (/home/llamabeast/discord-ai-bot/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:162:15)
at async handleMessage (file:///home/llamabeast/discord-ai-bot/src/bot.js:300:24)
at async Timeout._onTimeout (file:///home/llamabeast/discord-ai-bot/src/bot.js:107:16)

error on npm start: new Error("Used disallowed intents")

Followed setup instructions here
Ran npm i then npm start
Got error:

[Shard Manager] [INFO] Loading
[Shard #0] [INFO] Created shard
/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/@discordjs/ws/dist/index.js:1132
          error: new Error("Used disallowed intents")
                 ^

Error: Used disallowed intents
    at WebSocketShard.onClose (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/@discordjs/ws/dist/index.js:1132:18)
    at connection.onclose (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/@discordjs/ws/dist/index.js:676:17)
    at callListener (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/ws/lib/event-target.js:290:14)
    at WebSocket.onClose (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/ws/lib/event-target.js:220:9)
    at WebSocket.emit (node:events:514:28)
    at WebSocket.emitClose (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/ws/lib/websocket.js:260:10)
    at TLSSocket.socketOnClose (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/ws/lib/websocket.js:1272:15)
    at TLSSocket.emit (node:events:526:35)
    at node:net:337:12
    at TCP.done (node:_tls_wrap:657:7)

Node.js v20.9.0
/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/discord.js/src/sharding/Shard.js:178
        reject(new DiscordjsError(ErrorCodes.ShardingReadyDied, this.id));
               ^

Error [ShardingReadyDied]: Shard 0's process exited before its Client became ready.
    at Shard.onDeath (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/discord.js/src/sharding/Shard.js:178:16)
    at Object.onceWrapper (node:events:629:26)
    at Shard.emit (node:events:514:28)
    at Shard._handleExit (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/discord.js/src/sharding/Shard.js:439:10)
    at ChildProcess.emit (node:events:514:28)
    at ChildProcess._handle.onexit (node:internal/child_process:294:12) {
  code: 'ShardingReadyDied'
}

Node.js v20.9.0

ollama/discord bot/discord-ai-bot via  v20.9.0 on ☁️  [user]@gmail.com 
❯ node:events:492
      throw er; // Unhandled 'error' event
      ^

Error [ERR_IPC_CHANNEL_CLOSED]: Channel closed
    at new NodeError (node:internal/errors:406:5)
    at target.send (node:internal/child_process:754:16)
    at Client.<anonymous> (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/discord.js/src/sharding/ShardClientUtil.js:43:19)
    at Client.emit (node:events:514:28)
    at WebSocketManager.<anonymous> (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:271:19)
    at WebSocketManager.emit (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/@vladfrangu/async_event_emitter/dist/index.cjs:282:31)
    at WebSocketShard.<anonymous> (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/@discordjs/ws/dist/index.js:1173:51)
    at WebSocketShard.emit (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/@vladfrangu/async_event_emitter/dist/index.cjs:290:37)
    at WebSocketShard.onClose (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/@discordjs/ws/dist/index.js:1056:10)
    at connection.onclose (/Users/[user]/Documents/Mozilla/AI/localai/ollama/discord bot/discord-ai-bot/node_modules/@discordjs/ws/dist/index.js:676:17)
Emitted 'error' event on process instance at:
    at node:internal/child_process:758:35
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
  code: 'ERR_IPC_CHANNEL_CLOSED'
}

recall

whenever a conversation is started it mentions that we can clear using "@bot.clear" . This seems to trigger the bot again and it generated the summary of the previous response.
Screenshot 2024-01-09 175445

Processing txt files

Describe the feature
Process .txt files from Discord messages and send them as part of the request to Llama

Why do you think this feature should be implemented?
Discord has a 2000 characters limits, after that, it converts any text into a txt file. It would be great if the bot was able to process txt files and send them as part of the request to llama

Additional context
I encountered this potential feature improvement while trying to process code. Specifically, when trying to process the code of this bot.js using discord integration of ollama.

what is the benefit of a discord bot using a local llm

Hi - sorry for the naive question - I got this working and it's really cool - I'm trying to figure out what the benefit is of using a local llm (ollama) for a (non-local) discord channel. Can you shed some light on this?

custom SYSTEM message getting added to end of bot responses

Describe the bug
If you change SYSTEM string message in the .env file, it will add that string to the end of a response in discord after a couple prompts with the bot.

To Reproduce
Steps to reproduce the behavior:
-in .env change SYSTEM="you are a cat that likes fish"
-On discord @bot with question. It will respond appropriately as of it were a cat as expected.
-After 2nd or 3rd interaction the bot will start adding system string to end of its responses

Example:
User: "@catbot what are you"
Catbot: "I am a cat, meow.you are a cat that likes fish"

Expected behavior
Bot doesn't add system string to end of responses

Device

  • OS: windows 11

Additional context
Add any other context about the problem here.

how would i run this without the need for mentions?

sorry for the question i know its probably a simple solution but i really have no clue where to start with this discord api.
but i would like to run it in discord chat freely so it can reply to all the messages given.

is this possible?

SYSTEM="" Is prompted as a literal reply to the user

SYSTEM prompt is replied to the user with no context even when asked not to.

To Reproduce
Steps to reproduce the behavior:

  1. Write on SYSTEM="DO NOT WRITE THIS you are an assistant"
  2. Use the .env system by marking USE_SYSTEM as true and USE_MODEL_SYSTEM as false
  3. npm run
  4. If you say something that the bot doesnt recognice properly, they will start prompting what you asked them not to prompt

Expected behavior
Bot using SYSTEM prompt as INFO on how to act

Device

  • OS: Windows 10
  • Repo is latest (i downloaded as zip -> c6af204)
  • Ollama version 0.1.29 (windows preview)

Properly format discord channels and pings

Describe the feature
Currently the bot is incapable of pinging people despite frequently trying.

Currently before giving the message to the chatbot, you pre-process the discord tags like <#1082142594567516160> and <@280411966126948353> into #channel and @user, I suggest you add a step before sending the reply that goes the other way around.

Why do you think this feature should be implemented?
Ping other members who are relevant to the conversation and have clickable channel mentions

Additional context
I already implemented this on my fork, I would PR but I have made a ton of other changes that you probably don't want.

Here are the relevant lines https://github.com/CodeF53/sage/blob/006d5db453dc0119cc31d707390389a16f6b461f/src/aiRespond.ts#L127-L150, should be copy pasteable into your codebase

SyntaxError: Unexpected token '.'

npm start

start
node src/index.js

/home/user/ollama_discord_bot/node_modules/discord.js/src/client/BaseClient.js:29
userAgentAppendix: options.rest?.userAgentAppendix
^

SyntaxError: Unexpected token '.'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (/home/lee/ollama_discord_bot/node_modules/discord.js/src/index.js:6:22)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

Docker

Can we please have docker image for the same, i have no i dea how to do it and i dont seem to find the appropriate resources. Docker will be helpful considering it can just autostart on reboot and you can use your desktop without a terminal window always open

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.