AI / Machine Learning
-
July 25, 2023

How to Unlock the Potential of OpenAI API in Slack

Tracking long conversations in Slack and not missing important details can be challenging. Slack is a popular communication tool used by teams and organizations worldwide where a vast amount of information is exchanged. This is where the idea of Slack bots powered by AI comes in handy.

The goal of this project is to develop a proof of concept for summarizing a Slack thread using the OpenAI API. By leveraging the power of OpenAI GPT language models, the Slack plugin offers an efficient and intelligent thread summarization feature. With a simple command of "@Rs-GPT summarize," the plugin generates concise summaries of threaded conversations within Slack.

Proposed Solution

The project consists of a Node.js server that acts as a Slack bot using OpenAI's chat API to generate responses to user messages. The bot utilizes the @slack/bolt package for interacting with the Slack API and the openai package for communicating with OpenAI's API.

The bot listens to messages sent to it in a Slack channel and retrieves the conversation history for the channel using the Slack API. It sends the conversation history along with the system prompt to the OpenAI chat API to generate a response. The response is then sent back to the Slack channel as a message from the bot.

Here's the code snippet showcasing the summarizeHandler function used by the bot:

CODE: https://gist.github.com/kstoletniy/c09147e91b1a031b187c28f8c8204e6e.js?file=summarize.handler.ts


Supported Commands

The @Rs-GPT summarize command can summarize a thread conversation in the same language as the thread. It can also identify the speaker and include their statements in the summary.

Additionally, the /say command can be executed in your own chat to send a dedicated message to a specific channel. For example:

/say send kudos to the team for their incredible work in this sprint. to @project-channel

And the /hi command can be used to ask the AI any question and receive a response within seconds.

/hi how to implement in-app purchases in a ReactNative app?

Use Cases

The Slack plugin opens up numerous use cases, including:

  • Thread Summarization: The plugin can analyze the text written within the thread and generate a summary that captures the main points, key information, and important takeaways.
  • Quick Information Retrieval: Users can quickly retrieve summaries of previous threads they have participated in, saving time and effort in searching through long conversations.
  • Rapid Decision-Making: Users can employ the plugin to generate summaries of relevant threads, helping them grasp the context and arrive at informed conclusions efficiently.
  • Prioritizing Attention: The plugin can provide summarized versions of threads to help prioritize attention and focus on the most critical or relevant information.
  • Knowledge Consolidation: The plugin can summarize selected threads, facilitating knowledge synthesis and understanding.
  • Personal Note-taking: The plugin can summarize users' own contributions within a thread, helping them create personalized summaries for future reference or documentation purposes.
  • Collaborative Projects: Generating summaries of threads related to specific tasks or topics enables better coordination, clarity, and alignment among team members.
  • Learning and Training: The plugin can aid in knowledge transfer, retention, and providing accessible summaries for learners by summarizing educational or instructional threads.
  • Translate in your preferred language: While the summary results are in the main language by default, you can ask the bot to translate them into English or Spanish.

Advantages

Implementing a chatbot for Slack is straightforward with the available technical knowledge and documentation. Integrating the OpenAI API and sending the appropriate prompt is also simple with the help of the documentation. You can set the main language of the result and ask the AI to translate the summary to achieve more accurate and realistic responses. The AI can also recognize emojis and include them in the summary.

Challenges

There are some risks associated with this project.

OpenAI uses tokens as pieces of words for natural language processing. Depending on the model used, requests can use up to 4097 tokens shared between the prompt and completion (this limit is for the text-davinci-003 model). Therefore, if your prompt is 4000 tokens, your completion can be at most 97 tokens. If the API request exceeds the allowed token limit, it will crash.

To optimize the usage of tokens, one solution is to filter messages by removing unnecessary characters and mapping author names to small IDs.

The current implementation also controls the number of tokens that the prompt would take using the Tokenizer API. If the limit is exceeded, an error will be shown as is shown in the following peace of code.

CODE: https://gist.github.com/kstoletniy/5e9c8b3b3de6e0d6fbb85d704a74e06b.js?file=tokenizer.utils.ts

Additionally, the cost of using OpenAI could be high depending on usage. If the organization is large and it is used in multiple channels, it could increase the budget and easily reach the organization's usage limits.

Next Steps

Our goal is to continue working on improving the tool's functionality, adding new features, and enhancing its overall performance.

We are also planning to make it an open-source project, aiming to create a community around the project. Developers will be able to contribute to its development, and users can share their experiences and provide feedback.

Conclusions

In conclusion, the Slack thread summarizer with OpenAI integration is a great tool for improving productivity, streamlining communication, and reducing information overload.

We are excited about the potential of this project to make a positive impact on the way teams communicate, collaborate, and increase productivity in a simple way.

💡 Check out the POC repository and the demo link for more details about the project.

We look forward to sharing our progress with you and hearing your thoughts and feedback!