|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!
- 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.
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.
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.
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
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.
Copyright: Open AI made a statement about Copyright here: Will OpenAI claim copyright over what outputs I generate with the API? | OpenAI Help Center
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
- 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