This is a Mastodon chatbot that uses OpenAI to generate responses. The bot can post toots and DALL-E images based on a pre-written prompt or respond to direct mentions.
| ๐ค - Mastodon Mention Commands - ๐ค | โ๏ธ - License - โ๏ธ | ๐ - Updates - ๐ |
assumes you already have a Mastodon bot account and have your secret token, as well as an OpenAI API key
- Clone the repository:
git clone https://github.com/skullzarmy/chatGPToot.git
npm install
to initiate node and install dependenciesnpm run setup
will create needed folderscp .env.example .env
will copy .env.example to .env filenano .env
or use text editor to edit .env file and add your credentialsnano config.json
or use text editor to edit config.json file- IMPORTANT Your bot will toot about all of my blog posts if you do not edit this!
- I STRONGLY recommend running
npm run ingest-feeds
after adding a new RSS feed, or else it will toot about each new one it finds. There is no mechanism to modulate number or tempo, it will just spit them out! Ingesting the feed will add all existing items to local file memory, and check against that file for new items in the loop.
MASTODON_ACCESS_TOKEN=GET-FROM-MASTODON
MASTODON_API_URL=YOUR-MASTODON-INSTANCE
OPENAI_KEY=sk-...
MASTODON_ACCOUNT_ID=GET-FROM-MASTODON
MASTODON_ADMIN_ACCOUNT=TO-ENABLE-ADMIN-COMMANDS
MASTODON_ADMIN_ALERT_USERNAME=TO-ALERT-FOR-FEEDBACK
NEWSDATA_API_KEY=SET-UP-A-FREE-KEY-TO-GET-NEWS-DATA
#STATUS_API_TOKEN=GENERATE-NEW-PRIVATE-KEY-TO-AUTH-STATUS-REQUESTS
{
"rss_urls": ["http://YOUR-RSS-FEED-URL/rss"],
...
}
(top)
The following arguments are available for app/chatgptoot.js:
--no-loop
- Disables the automatic toot, image, and mention loops. This is useful if you want to run the script manually to test it.
--no-image
- Disables the automatic image loop.
--no-toot
- Disables the automatic toot loop.
--no-mention
- Disables the automatic mention loop.
--no-rss
- Disables the RSS checker loop.
--toot-now
- Generates a toot and posts it immediately.
--image-now
- Generates an image prompt and posts it immediately.
(top)
npm run bot
will run the bot in a loop, tooting, mentioning, and posting images.
npm run bot-mention
will run the bot in a loop, mentioning but not tooting or posting images.
npm run bot-image
will run the bot in a loop, posting images but not tooting or mentioning.
npm run bot-toot
will run the bot in a loop, tooting but not mentioning or posting images.
npm run single-toot
will run the bot once, tooting but not mentioning or posting images.
npm run single-image
will run the bot once, posting images but not tooting or mentioning.
npm run single-mention
will run the bot once, mentioning but not tooting or posting images.
npm run tail-logs
will stream the new bot logs to your terminal.
npm run usage
will generate a usage report located in reports/
(top)
The bot supports the following commands when responding to a mention:
command must be at the beginning of the mention (after the @mention)
- "{prompt}" - Bot will respond to direct mentions. If no command is used, bot will use your mention text and generate a chat completion for reply.
- "//img// {prompt}" or "//image// {prompt}" - Treats as an image prompt, generates a DALL-E image, and posts it in reply
- "//img-asst// {prompt}" or "//image-assist// {prompt}" - Asks GPT-3 to revise your idea into a new image prompt, then sends for DALL-E image generation and returns image and prompt in reply.
- "//news//" โ For now this only checks for a few articles with keywords "gpt OR ai OR llm OR openai OR copilot OR midjourney" in Science or Technology categories. It will then read and summarize them for you. I plan to expand this to take prompts for search criteria but the news API costs $$. Feel free to buy me a beer to help support the development!
- "//feedback// {feedback}" - Logs user feedback for review
- "//beta//" or "//beta-application//" - Posts the application link to the user
- "//help//" or "//commands//" - Posts a list of commands in reply
(top)
- "//toot-now// {prompt}" - Posts a new toot to main bot account using given prompt
- "//image-now// {prompt}" - Posts a new image to main bot account using given prompt
- "//status//" - Replies with a status message.
@chatGPToot //image// a cat eating a taco
(top)
By default, the bot will log all usage to logs/usage_logs.json
npm run usage
will print and save a usage summary to reports/
(top)
Bot can now subscribe to RSS feeds, track previously known items, and generate toots about newly found items in the feed.
Modify the config.json file and add any number of RSS feeds to follow. Be careful! It will auto-post all newly found items without any care in the world about spamming everyone!
This project is released under the MIT License. You are free to use, modify, and distribute the source code, subject to the terms and conditions of the license.
The MIT License is a permissive open-source software license that allows you to use this project for any purpose, including commercial use. By using this project, you agree to retain the original copyright notice and the full license text in all copies or substantial portions of the software.
We encourage collaboration and contribution to the project. Feel free to fork, modify, and share your improvements with the community. Our goal is to make this software as useful and accessible as possible, and your contributions will help us achieve that.
Please note that this project is provided "as is" without any warranty or liability. The authors are not responsible for any consequences that may arise from the use of this software.
(top)
Overall, the script looks well-structured and functional. However, I found a few improvements and potential issues that should be addressed:
Some function names are in camelCase (e.g., handleImageCommand), while others use underscores (e.g., logUsage). It's best to maintain consistency in naming conventions.
- Implement redis for persistent bottleneck rate limiting
- Implement fs/promise in chatgptoot.js (download image broke)
- Consider restricting news injection in toot generation to specific times so toots are not always news related.
(top)
- 2023-04-13
- Removed dependency for deprecated
requests
package. This required refactoring thenode-mastodon
package, which has been abandoned. I removed the dependency on this package and added modules/tusk/ which is largely the same code, refactored to use axios and utilize the vanilla js Promise functionality. Dependabot can leave me alone about it now. - Setup an express server that serves a status JSON object. It checks my blog site and the bot node process and returns current status messages for both.
- Added RSS feed subscription. Define RSS URLs in config.json
- Bot account was suspended, so I moved to a new account on @botsin.space. Bot is renamed Mr. Roboto (@mrroboto). I have decided not to change the repo name. Botsin.space does not enable the
trending/tags
API endpoint, which was used inaddContext()
, so I commented out thegetTrendingTags()
call but left it in place for running on instances that do support it. I may go to the trouble of setting up a separate account on another instance just to get trending tag data, but I highly doubt it. - Instead of trending tags, I added a news checker app/news_handler.js which will return the latest news.
addContext()
is making use of this now to enrich the chat completion's context. I have noticed it is more heavily weighing the output than I would like, so I may consider putting some trigger variable into the function invocation to control weather I want the news added or not. Then set some mechanism for deciding which of the scheduled toots will be news related. Maybe I will setup a whole separate loop for it.
- Removed dependency for deprecated
(top)