Giter VIP home page Giter VIP logo

chatgptoot's Introduction

chatGPToot ๐Ÿฆฃ -- Mastodon OpenAI Chatbot ๐Ÿค–

GitHub issues GitHub pull requests

Description

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.

Custom badge

Mastodon Follow Mastodon Follow


| ๐Ÿค– - Mastodon Mention Commands - ๐Ÿค– | โš–๏ธ - License - โš–๏ธ | ๐Ÿ†• - Updates - ๐Ÿ†• |


Stats

Lines of Code Repo Size File Count


Dependencies

Bot

GitHub package.json dependency version (prod) GitHub package.json dependency version (prod) GitHub package.json dependency version (prod) GitHub package.json dependency version (prod) GitHub package.json dependency version (prod) GitHub package.json dependency version (prod) GitHub package.json dependency version (prod) GitHub package.json dependency version (prod) GitHub package.json dependency version (prod)

Status Server

GitHub package.json dependency version (prod) GitHub package.json dependency version (prod) GitHub package.json dependency version (prod)

Installation

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 dependencies
  • npm run setup will create needed folders
  • cp .env.example .env will copy .env.example to .env file
  • nano .env or use text editor to edit .env file and add your credentials
  • nano 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.

.env

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

config.json

{
    "rss_urls": ["http://YOUR-RSS-FEED-URL/rss"],
    ...
}

(top)

Arguments

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)

Example Usage

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)

Mention Commands ๐Ÿค–

The bot supports the following commands when responding to a mention:

command must be at the beginning of the mention (after the @mention)

Following Only (bot account must follow user sending command)

  • "{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)

Admin Only

  • "//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.

Example

@chatGPToot //image// a cat eating a taco

a cat eating a taco

(top)

Usage Logging Utilities

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)

RSS Feed Subscription

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!

License โš–๏ธ

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)



GPT-4 Suggested Improvements

Overall, the script looks well-structured and functional. However, I found a few improvements and potential issues that should be addressed:

Function naming consistency:

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.

To Do

  • 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)

Updates

  • 2023-04-13
    • Removed dependency for deprecated requests package. This required refactoring the node-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 in addContext(), so I commented out the getTrendingTags() 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.

(top)

chatgptoot's People

Contributors

skullzarmy avatar

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.