Giter Site home page Giter Site logo

dexaai / xbot Goto Github PK

View Code? Open in Web Editor NEW
17.0 1.0 2.0 738 KB

Twitter / X bot for responding to user mentions with AI-generated answers.

Home Page: https://twitter.com/AskDexa

License: MIT License

TypeScript 99.54% JavaScript 0.16% Shell 0.30%
ai dexa twitter twitter-bot

xbot's Introduction

@AskDexa on Twitter Build Status MIT License Prettier Code Formatting

X Bot

Twitter / X bot for responding to user mentions with AI-generated answers.

Features

  • extremely robust (used on an acct w/ 150k+ followers)
  • supports multiple AI answer engines: openai, dexa, and perplexity
  • persists state to redis and caches all twitter objects to maximize quota usage
  • maximizes twitter api throughput w/ plan-dependent throttling
  • resolves structured entity data to give answer engines additional context
    • includes things like links, twitter user profile info, quote tweets, etc
  • handles bot interactions such as:
    • basic @mentions
    • follow-up questions
    • referencing quote tweets and retweets
    • referencing mentioned users
    • referencing content from links
    • referencing content from embedded media (images, gifs, video; polls not yet supported)
  • uses a scoring heuristic for prioritizing which tweets to respond to when the bot goes viral
  • ignores known bot accounts to prevent them from endlessly replying to each other
  • supports running multiple bots w/ the same redis instance
  • thoroughly tested in production

Configuring the bot

You'll need a paid Twitter developer account and a Twitter v2 app with OAuth 2.0 enabled. You'll need to subscribe to at least the basic Twitter API plan in order to run this bot; the free tier is not supported since it doesn't support fetching tweets which is required for this bot to work.

Set up a .env file by copying .env.example and initializing all required environment variables.

Dependencies to call out:

  • Nango is used to simplify Twitter OAuth
  • OpenAI chat completions API is used as the default answer engine
  • Dexa is an excellent answer engine whose API is currently in private beta (otherwise it would be the default)
  • Redis is used to persist state across runs and cache twitter objects (tweets, users, mentions) in order to maximize our use of twitter API quotas
    • Redis is optional, and if you don't specify a redis instance, state will be "persisted" to an in-memory store
    • However, given twitter's quotas, using a redis instance to cache twitter objects is highly recommended

Setting TWITTER_API_PLAN to the correct plan is important, because this is used to determine the bot's internal twitter API throttling in order to avoid rate limits and maximize quota usage.

Running the bot

tsx bin/xbot.ts
Usage:
  xbot [flags...]

Flags:
  -a, --answer-engine <string>                      Answer engine to use (openai, dexa, or perplexity) (default: "openai")
      --debug                                       Enables debug logging
  -t, --debug-tweet-ids <string>                    Specifies a tweet to process instead of responding to mentions with
                                                    the default behavior. Multiple tweets ids can be specified (-t id1
                                                    -t id2 -t id3). Exits after processing the specified tweets.
  -d, --dry-run                                     Enables dry run mode, which will not tweet or make any POST requests
                                                    to twitter
  -e, --early-exit                                  Exits the program after resolving the first batch of mentions, but
                                                    without actually processing them or tweeting anything
  -f, --force-reply                                 Forces twitter mention validation to succeed, even if the bot has
                                                    already responded to a mention; very useful in combination with
                                                    --debug-tweet-ids
  -h, --help                                        Show help
  -n, --max-num-mentions-to-process <number>        Number of mentions to process per batch (default: 10)
      --no-mentions-cache                           Disables loading twitter mentions from the cache (which will always
                                                    hit the twitter api)
  -R, --resolve-all-mentions                        Bypasses the tweet mention cache and since mention id state to fetch
                                                    all mentions from the twitter api
  -s, --since-mention-id <string>                   Overrides the default since mention id

TODO

  • understand why mentions from non-verified accounts aren't being reported by the twitter api
  • fix support for empty mentions
    • currently works but duplicates the previous tweet's contents
  • support url entities
    • expand them with metadata
  • support media entities
    • populate media entities
    • for openai, use gpt-4-vision-preview
    • conditionally preprocess images using sharp to ensure they are supported by gpt4v
  • improve openai answer engine
    • dalle tool
    • code interpreter tool
    • midjourney tool
    • dexa tool
    • perplexity tool
    • serper tool
    • tweet search tool
    • twitter user search tool
  • support URLs and other entity metadata (user profile info) so the answer engine has more context to work off of
  • support use case of answering questions about linked podcast episodes
  • consider re-adding support for generating images to support longer responses w/ the openai answer engine
    • could use a binary classifier or tool to determine whether or not to render the response as an image

License

MIT © Dexa

xbot's People

Contributors

rileytomasek avatar transitive-bullshit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

xbot's Issues

Issue: SCRAPER_API_BASE_URL

Hey, great application, thanks for sharing.

I'm getting this error, can't see where I'd need a base URL here? Thanks.

tsx bin/xbot.ts --answer-engine openai -t interzonez 

error unknown SCRAPER_API_BASE_URL is required Error: SCRAPER_API_BASE_URL is required
    at ScraperClient (/Users/amh17/xbot/src/services/scraper-client.ts:45:13)
    at <anonymous> (/Users/amh17/xbot/src/entities.ts:341:23)
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
    at async loadESM (node:internal/process/esm_loader:42:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

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.