Giter Site home page Giter Site logo

pedrorito / chatgptslackbot Goto Github PK

View Code? Open in Web Editor NEW
385.0 15.0 68.0 34 KB

๐Ÿค– A Slack bot that integrates with OpenAI's ChatGPT to provide answers, written in Python

License: GNU General Public License v2.0

Dockerfile 12.45% Python 87.55%

chatgptslackbot's Introduction

ChatGPT for Slack Bot

playwright-version license

This is a simple Slackbot that uses the acheong08/ChatGPT revChatGPT package to respond to messages in Slack. It is designed to be used with the Slack Events API, and it listens for app_mention events, which are triggered when a user mentions the bot in a Slack channel.

When the bot receives a app_mention event, it extracts the user's message from the event payload, sends it to the revChatGPT package to generate a response, and then sends the response back to the user via Slack.

The revChatGPT package is used to handle authentication and communication with the GPT-3 API, and it is also used to refresh the session with the GPT-3 API on a regular basis. This is done in a separate thread to prevent the session from expiring while the bot is handling requests.

Usage

To use the bot, you will need to install the dependencies and set the OPENAI_API_KEY environment variable that you can get from https://platform.openai.com/account/api-keys. You also need to set SLACK_SIGNING_SECRET and SLACK_BOT_TOKEN environment variables after creating the Slack App. You can then run the app.py script to start the bot.

pip install -r requirements.txt
export SLACK_SIGNING_SECRET=slack_signing_secret
export SLACK_BOT_TOKEN=slack_bot_token
export OPENAI_API_KEY=you_openai_api_key
python app.py

Alternatively, you can use the containerized version by setting the environment variables in the variables.env file and then run

docker-compose up -d

Once the bot is running, you can mention it in a Slack channel to send it a message. For example, you can type @my-bot hello to send the message "hello" to the bot. The bot will respond with a generated message based on the GPT-3 model.

ChatGPT Configuration

The ChatGPTConfig dictionary at the top of the app.py script contains the configuration for the revChatGPT package. It specifies the API token for the OpenAI account that the bot will use to authenticate with the GPT-3 API. The value is read from the OPENAI_API_KEY environment variable.

The conversation_id parameter in the Chatbot constructor is used to specify the ID of the conversation that the bot should use. If this parameter is not provided, the revChatGPT package will generate a new conversation ID for each message that the bot receives.

Slack Configuration

By default, app.py is exposing port 4000 for Slack events. You may change the port number in the end of the script.

To configure the Slack App, follow these example instructions from the official SlackApi GitHub account.

For this bot, the required Scopes in OAuth & Permissions are:

  • app_mentions:read
  • chat:write
  • im:write

For direct message required & config :

  • Enable bot direct messages go to : Features -> App Home -> (Enable) Messages Tab
  • OAuth & Permissions im:history and message:im

In the Event Subscriptions, you need to subscribe to the app_mention event.

Limitations

The bot uses a pre-trained GPT-3 model, which means that its responses are limited to the information that is contained in the model. It may not be able to respond accurately to messages that are outside the scope of the pre-trained model.

Notes

The tls-client python library that is used by the revChatGPT package does not currently support ARM architectures. As a result, the bot may not be able to run on devices with ARM processors. This limitation will be addressed in a future update.

Disclaimer

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

License

This project is released under the terms of the GPL 2.0 license. For more information, see the LICENSE file included in the repository.

chatgptslackbot's People

Contributors

l0ginp avatar pedrorito avatar ralphmao avatar raymondchen625 avatar sanchezg avatar sheevy avatar sztanko avatar wantaekchoi avatar

Stargazers

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

Watchers

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

chatgptslackbot's Issues

Docker image size is too big

The image size is more than 2GB. Can you try to reduce it?

chatgptslackbot                             latest              90630876b727        8 days ago           2.14GB

Docker compose error

Traceback (most recent call last):
chatgptslackbot | File "/app/app.py", line 15, in
chatgptslackbot | chatbot = Chatbot(ChatGPTConfig, conversation_id=None)
chatgptslackbot | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
chatgptslackbot | File "/usr/local/lib/python3.11/site-packages/revChatGPT/revChatGPT.py", line 116, in init
chatgptslackbot | self.refresh_session()
chatgptslackbot | File "/usr/local/lib/python3.11/site-packages/revChatGPT/revChatGPT.py", line 295, in refresh_session
chatgptslackbot | asyncio.run(self.get_cf_cookies())
chatgptslackbot | File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
chatgptslackbot | return runner.run(main)
chatgptslackbot | ^^^^^^^^^^^^^^^^
chatgptslackbot | File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
chatgptslackbot | return self._loop.run_until_complete(task)
chatgptslackbot | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
chatgptslackbot | File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
chatgptslackbot | return future.result()
chatgptslackbot | ^^^^^^^^^^^^^^^
chatgptslackbot | File "/usr/local/lib/python3.11/site-packages/revChatGPT/revChatGPT.py", line 370, in get_cf_cookies
chatgptslackbot | browser = await p.chromium.launch(headless=False)
chatgptslackbot | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
chatgptslackbot | File "/usr/local/lib/python3.11/site-packages/playwright/async_api/_generated.py", line 12809, in launch
chatgptslackbot | await self._impl_obj.launch(
chatgptslackbot | File "/usr/local/lib/python3.11/site-packages/playwright/_impl/_browser_type.py", line 93, in launch
chatgptslackbot | Browser, from_channel(await self._channel.send("launch", params))
chatgptslackbot | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
chatgptslackbot | File "/usr/local/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 44, in send
chatgptslackbot | return await self._connection.wrap_api_call(
chatgptslackbot | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
chatgptslackbot | File "/usr/local/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 419, in wrap_api_call
chatgptslackbot | return await cb()
chatgptslackbot | ^^^^^^^^^^
chatgptslackbot | File "/usr/local/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 79, in inner_send
chatgptslackbot | result = next(iter(done)).result()
chatgptslackbot | ^^^^^^^^^^^^^^^^^^^^^^^^^
chatgptslackbot | playwright._impl._api_types.Error: Executable doesn't exist at /root/.cache/ms-playwright/chromium-1033/chrome-linux/chrome
chatgptslackbot | โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
chatgptslackbot | โ•‘ Looks like Playwright was just installed or updated. โ•‘
chatgptslackbot | โ•‘ Please run the following command to download new browsers: โ•‘
chatgptslackbot | โ•‘ โ•‘
chatgptslackbot | โ•‘ playwright install โ•‘
chatgptslackbot | โ•‘ โ•‘
chatgptslackbot | โ•‘ <3 Playwright Team โ•‘
chatgptslackbot | โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

Install instructions

Do you mind providing some instructions on how to succesfully integrate this into slack, i.e. once the bot is running locally, how to integrate it with Slack

ValueError revChat

ValueError revChat, even though I put the auth details on docker file, still couldn't find the auth details.

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.