![]() |
Summary | A cloud chatbot adaptor for Discourse, currently supporting OpenAI |
![]() |
Repository Link | GitHub - merefield/discourse-chatbot: A cloud chatbot adaptor for Discourse, currently supporting OpenAI |
![]() |
Install Guide | How to install plugins in Discourse |
EARLY ACCESS: This is early days for this plugin. Itās great to have help with testing and feedback. Production use should be ok now but expect minor issues. The most egregious ones should be fixed now!
Known Issues:
- Persistent notifcation on Bot DM channel that wonāt go away (almost certainly a core bug Discourse team is working on ⦠to do with length of messages not fitting in screen - workaround on desktop is to maximise the chat window :tada)
- May not work in multi-site configurations.
-
Code doesnāt handle it well when you delete the bot user.fixed!
-
Deleted posts and messages: the bot canāt handle these at presentshould be fixed
-
in Direct Message channels the bot is over intrusive and will presently try to reply to everything. This is being worked on.Iāve released a fix for this, so you might want to test it out to confirm. -
Strange responses that appear to suggest the post history is being gathered from different topicsIāve since released a fix.
What is it?
A plugin that uses a cloud-based chatbot to provide a fun and sometimes useful interactive AI experience.
(Sorry China!

Is extensible and supporting other cloud bots is intended (hence the generic name for the plugin), but currently āonlyā supports interaction with Open AI Large Language Models (LLM) such as āChatGPTā and GPT3. This may change in the future. Please contact me if you wish to add additional bot types or want to support me to add more. PR welcome.
Setup
There is some minor setup required before you can use the bot: take a moment to read through the entire set of Plugin settings.
For AIbot to work in Chat you must have Chat enabled.
OpenAI
You must get a token from https://platform.openai.com/ in order to use the current bot. A default language model is set (one of the most sophisticated), but you can try a cheaper alternative, the list is here
There is an automated part of the setup: upon addition to a Discourse, the plugin currently sets up a AI bot user with the following attributes
- Name: āAIBotā
- User Id: -4
- Bio: āHi, Iām not a real person. Iām a bot that can discuss things with you. Donāt take me too seriously. Sometimes, Iām even right about stuff!ā
- Group Name: āai_bot_groupā
- Group Full Name: āAI Botsā
You can edit the name, avatar and bio (see locale string in admin ā customize ā text) as you wish but make it easy to mention.
Itās not free, so thereās a quota system, and you have to set this up
Initially no-one will have access to the bot, not even staff.
Calling the Open AI API is not free after an initial free allocation has expired! So, Iāve implemented a quota system to keep this under control, keep costs down and prevent abuse. The cost is not crazy with these small interactions, but it may add up if it gets popular. You can read more about OpenAI pricing on their pricing page.
Example calculations can be found in this post:
In order to interact with the bot you must belong to a group that has been added to one of the three levels of trusted sets of groups, low, medium & high trust group sets. You can modify each of the number of allowed interactions per week per trusted group sets in the corresponding settings.
You must populate the groups too. That configuration is entirely up to you. They start out blank so initially no-one will have access to the bot:
In this example Iāve made staff
have high trust access, whilst trust_level_0
have low trust. They get the corresponding quotas in three additional settings.
Note the user gets the quota based on the highest trusted group they are a member of.
āPrompt Engineeringā
There are several locale text āsettingsā that influence what the bot receives and how the bot responds.
The most important one you should consider changing is the botās system
prompt. This is sent every time you speak to the bot.
You can try a system prompt like:
āYou are an extreme Formula One fan, you love everything to do with motorsport and its high octane levels of excitementā instead of the default.
Try one that is most appropriate for the subject matter of your forum. Be creative!
Changing these locale strings can make the bot behave very differently but cannot be amended on the fly. I would recommend changing only the system prompt as the others play an important role in providing information on who said what to the bot.
NB In Topics, the first Post and Topic Title are sent in addition to the window of Posts (determined by the lookback setting) to give the bot more context.
You can edit these strings in Admin ā Customize ā Text under chatbot.prompt.
Supports both Posts & Chat Messages!
The bot supports Chat Messages and Topic Posts, including Private Messages (if configured).
You can prompt the bot to respond by replying to it, or @ mentioning it. You can set how far the bot looks behind to get context for a response. The bigger the value the more costly will be each call.
Thereās a floating quick chat button that connects you immediately to the bot. Its styling is a little experimental (modifying some z-index values of your base forum on mobile) and it may clash on some pages. This can be disabled in settings. PR welcome to improve how it behaves.
Disclaimer: Iām not responsible for what the bot responds with. Consider the plugin to be at Beta stage and things could go wrong. It will improve with feedback. But not necessarily the bots response Please understand the proās and conās of a LLM and what they are and arenāt capable of and their limitations. They are very good at creating convincing text but can often be factually wrong.
Important Privacy Note: whatever you write on your forum may get forwarded to Open AI as part of the bots scan of the last few posts once it is prompted to reply (obviously this is restricted to the current Topic or Chat Channel). Whilst it almost certainly wonāt be incorporated into their pre-trained models, they will use the data in their analytics and logging. Be sure to add this fact into your forumās TOS & privacy statements. Related links: Terms of use, Privacy policy, OpenAI API
Copyright: Open AI made a statement about Copyright here: Will OpenAI claim copyright over what outputs I generate with the API? | OpenAI Help Center
TODO/Roadmap Items
-
Add front and back-end tests
-
Add extra logic to convert suspected usernames into @ mentions (@frold )
-
forgot to mention the bot? Get bot to respond to edits that add its @ mention (@frold )
-
Add a badge? You did mention @botname (@frold )
-
Add setting to include Category and Pinned Posts prompt? (@Ed_S)
-
Ditto Bios to each message history prompt? (@Ed_S , @codergautam). Will this even work. Letās get evidence.
-
Update Discourse Frotz with this better codebase?
-
Add support for ChatGPT -
Lint the plugin to Discourse core standards -
Add CI workflows -
Add settings to influence the nature of the bots response (e.g. how wacky it is). -
include Topic Title & first Posts to prompt -
Add setting to switch from raw Post/Message data to cooked to potentially leverage web training data better (suggestion by @MarcP). NB May cost more and limit what is returned as input tokens are counted and cooked is much bigger.think weāve abandoned this idea
Credits:
- Thanks to @MarcP for his enthusiastic support and detailed testing feedback.
- The guys whoāve contributed to the emerging standard Ruby API for Open AI which this leverages
- The floating button design is mostly taken from Discourseās own GitHub - discourse/material-design-stock-theme (so they are not currently compatible, doh!)
- The fixtures code is based on @vinothkannans work here
- If @P16 hadnāt hired me many moons ago to help him with a chat bot this might not exist