This project implements a Slack bot that integrates with OpenAI's GPT models to respond to user mentions.
- Framework: Uses Flask as the web server and Slack Bolt for Python to handle Slack events.
- Trigger: Listens for
@app_mention
events in Slack channels where the bot is present. - Processing:
- Extracts the user's message from the event payload.
- Sends the message as a prompt to the OpenAI Chat Completions API (
gpt-3.5-turbo
model). - Includes a system prompt identifying the bot as a helpful assistant from the "Stanford Technology Training team".
- Response: Posts the generated response from OpenAI back to the originating Slack channel as a reply in the thread.
- Dependencies:
Flask
,openai
,slack_bolt
,slack_sdk
,gunicorn
.
cinethinker.py
: A command-line interface script to interact directly with a specific, pre-existing OpenAI Assistant (using the Assistants API). This is separate from the main Slack bot functionality.slack-api-langchain
: An alternative implementation of the Slack event handler, also using Flask. This version utilizes LangChain (ChatOpenAI
) for interacting with the GPT model and includes features like reaction emojis and optional broadcasting of replies to dedicated channels.
-
Environment Variables: The application requires the following environment variables to be set:
OPENAI_API_KEY
: Your OpenAI API key.SLACK_BOT_TOKEN
: Your Slack bot token.SLACK_SIGNING_SECRET
: Your Slack app's signing secret.PORT
(Optional): The port for the Flask server (defaults to 3000 inmain.py
or 8080 inslack-api-langchain
).- The
slack-api-langchain
script also usesOPENAI_ORGANIZATION
(required),GPT_MODEL
(optional), andDEDICATED_CHANNELS
(optional).
-
Dependencies: Install the required Python packages:
pip install -r requirements.txt
-
Running:
- To run the main Slack bot (
main.py
):gunicorn main:flask_app # or for development: # python main.py
- To run the terminal chat (
cinethinker.py
):python cinethinker.py
- Ensure your Slack App is configured to send events to the correct
/slack/events
endpoint of your running Flask application.
- To run the main Slack bot (