Giter VIP home page Giter VIP logo

openai-slackbot's Introduction

OpenAI API integration with SlackBot

Usage

  1. Create your own .env based on .env.sample . The following keys must be configured:
# See https://api.slack.com/start/building/bolt-python
SLACK_BOT_TOKEN=xoxb-your-Bot-User-OAuth-Token
SLACK_SIGNING_SECRET=your-signing-secret

# See https://beta.openai.com/account/api-keys
OPENAI_API_KEY=your-openai-api-key

# NGROK
NGROK_AUTHTOKEN=your-ngrok-token
  1. Then docker compose up:
docker compose up -d
  1. Get the Ngrok URL:
python3 get_ngrok_url.py
#Output: https://xxxx-xxx-xxx-xxx-xx.xx.ngrok.io
  1. Goto your Slack App "Event Subscriptions" page and put the Ngrok URL into the "Request URL". And add "Subscribe to bot events". If verified successfully, you will be able to "Save Changes".

  1. Done! You can now direct message the bot or add the bot to your channel(s). It will reply to the conversation thread.

Slack App Setup

To create Slack App, see this example. Refer to the sections from "Create a Slack app" to "Save your apps credentials".

For this particular app, it need the following Bot Token Scopes:

If you want to direct message the bot, enable the followings:

Remember to "Reinstall to Workspace".

Ngrok Authtoken

OpenAPI API keys

More

You can also play around with other settings:

# Some of the OpenAI params
OPENAI_API_ENGINE=text-davinci-003
OPENAI_API_MAX_TOKENS=1024
OPENAI_API_TEMPERATURE=0
OPENAI_API_TOP_P=1
OPENAI_API_N=1

# Bot
BOT_MAX_WORKERS=5
BOT_PORT=3000

# The max number of chars to send in the request history. Note the larger the value, the more tokens may be consumed. According to OpenAI, 1 token is ~4 chars. So 2000 chars is ~500 tokens
BOT_MAX_HISTORY_CHARS=2000

# For debug, if set to true, the bot will dump the whole JSON response in slack message
BOT_REPLY_IN_JSON=False

## For debug, if set to true, the bot will append meta data in the in slack message
BOT_REPLY_SHOW_META=False

Local development using venv

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
ngrok http 3000
python3 bot.py

Screenshots

Here is a sample output of asking the bot to generate a login page.

After deleting the wrong tailwind integrity checksum, the generated HTML actually not bad:

Disclaimer

This is a personal project for fun and is not affiliated with OpenAI or Slack in any way.

openai-slackbot's People

Contributors

scottykwok avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

meetingattendee

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.