- If you don’t have Python installed, install it from here OR
- LINUX:
$ sudo apt-get install python3- MAC:
$ brew install python- WINDOWS: gotta use the website + .exe lol
- Install OpenAI
pip install openai
-
Clone this repository
-
Navigate into the project directory
$ cd chatGPT-help-bot -
Create a new virtual environment
$ python -m venv venv $ . venv/bin/activate -
Install the requirements
$ pip install -r requirements.txt
-
Make a copy of the example environment variables file
$ cp .env.example .env
-
Add your OpenAI API key to the newly created
.envfile -
Add your Twitter API keys to the
.envfile -
Add your Discord token to the
.envfile -
Add your postgresql credentials (use pgAdmin4 for gui db interaction) to the
.envfile. Also add the RENDER credentials where applicable for the database hosted non-locallyPOSTGRESQL_HOST-> localhost currently fine to leavePOSTGRESQL_PORT-> 5433 currently fine to leave (5432 = postgres def)
POSTGRES_USER-> username of your database table ownerPOSTGRES_PASSWORD-> password of your database table owner
- Edit
config.ymlwith desired run parameters - the most important are:
ADD_RULE-> add a mention to trackADD_TAG-> update the tag for which all tweets matching the rule is stored underREMOVE_RULE-> remove a mention to trackaccount_to_query-> primary twitter account to track mentions of on initdb_name-> the name of your database or postgresql servertable_name-> the name of the table in your database or serverchat_channel_id-> default channel if none is entered in UI or permissions not attained (lower case) - this is used to query the questions and user inptusdata_channel_id-> this is the channel to use in order to answer the questiontweet_history-> number of tweets from archive you want to pull (more = longer process time)
(for
app.pydiscord and chatGPT use -> editparams.ymlas well
prompt-> details of what question you want to ask chatGPT
- Create db and table (if not present) - use pgAdmin4 for easiest interaction OR use postgresql if comfortable.
config.yml-> update db_name and table_name to values from previous step
In pgAdmin4 or postgresql:
- Create server on
localhost:5433/with yourdb name,username, andpassword - Populate the
metrics_table_nameandaggregated_table_namewith your database values inconfig.yml
You can follow the pgadmin4 steps to setup your own - or you can import df_table.csv to your postgresql server (untested)
- Run the app for discord history based AI responses
$ python3 app.pyYou should now see three .txt files as well as terminal outputs, the .txt files are labeled appropriately:
tweets.txtholds tweet history infodiscord.txtholds discord channel history infooutput.txtthat will hold the chatGPT responses
- Run the app for twitter listener bot + database update
$ python3 utils/filtered_stream.py- Update rules while running stream - in
config.yml:
- update
ADD_RULE: with your @account or #tag to add - update
ADD_TAG: with the project name/tag
$ python3 utils/update_rules.py- Remove rules while running stream - in
config.yml:
- update
REMOVE_RULE: with your @account or #tag to remove
$ python3 utils/remove_rules.pyCurrently if updated metrics are detected we are updating the entire existing data table. We may want to change this to only update the row for efficiency. Two primary files are:
app.py-> ui + discord + search_tweets() + gpt interactionutils/filtered_stream.py-> stream for engagement metrics to dbthis and it's associated files are the current development focus.
Other standalone functions for testing include:
update_database.pyto update a specific tweet's metric dataui.pyto run standalone UI for discord + gpt interactionapp.pyto run discord + gpt interaction E2E (ui commented - see config.yml)
There are three user's currently identified in the tweet tracking logic of filtered_stream.py
author= originator of the tweet being trackedincluded= the author of the tweet included (retweeted, quoted, replied to, mentioned, etc.)engager= currently should return the same as the above two - as well as any other accounts mentioned in the tweet.engager could be used in the future to reward all users mentioned instead of just author + engager it is currently used to confirm that the author of the included tweet is indeed that author - could be used to reward tweet being engaged more than engager via multiplier as decided.
There are 6 columns in the table - all self explanatory expect:
index= engager @usernameauthor= included author's display nameTweet ID= id used to track and aggregate metrics per tweet
TODO: create another table that holds the users and aggregates all tweet IDs belonging to a user - and their metrics - to user
Currently only one resposne is stored and replaced each time. This may be changed to preserve response history for better future answering depending on database decisions.
Here is an example pet name generator app used in the OpenAI API quickstart tutorial. It uses the Flask web framework. Check out the tutorial or follow the instructions below to get set up. This example was stripped as a starting place for this project.