Package: chatiq
ChatIQUsage|Prerequisites|Installation|Development|Deployment|Configuration|Limitations|FAQ|Tips|Changelog|LicenseChatIQ is a versatile Slack bot using GPT & Weaviate-powered long-term memory to accomplish various tasks.FeaturesProvides Home view for configurations.Extracts context from the channel description and topic.Uses OpenAI's GPT model for generating responses.Reads conversation replies in the mentioned thread.UsesWeaviateto store conversations in long-term memory.Stores titles and previews of unfurling links in long-term memory.Stores plain text and PDF file attachments in long-term memory.Detects channel privacy to keeps private conversations within the channel.Support integrating with existingFlaskorBoltapplications.Easily deployable to Kubernetes using provided configurations.How to UseConfigure workspace settingsClick ChatIQ app to configure Slack workspace settings in App Home.Invite ChatIQ to your preferred channelsEnter/invite @ChatIQto invite ChatIQ to Slack channels.Configure channel settingsUse emojis in Slack channel topics and descriptions to override workspace settings.Use :thermometer: for temperature, :round_pushpin: for timezone and :speech_balloon: for system message to override workspace settings.Override channel descriptions by channel topics. (channel topic > channel description > app home in priority)Start conversationMention@ChatIQto start conversation.PrerequisitesPython 3.10A Slack bot tokenAn OpenAI API keyA Weaviate instanceA PostgreSQL instanceWeaviate SetupIf you plan to run the chatbot locally without Docker Compose or Kubernetes, you will need to set up a Weaviate instance. Follow theinstructionsto install and configure Weaviate.When running the chatbot with Docker Compose or Kubernetes, no additional setup is required for Weaviate as it is included in the configurations.PostgreSQL SetupThe chatbot requires a PostgreSQL database to store OAuth tokens and state information. If you're running the bot locally without Docker Compose or Kubernetes, you will need to set up and configure a PostgreSQL instance. Please refer to theofficial PostgreSQL documentationfor installation instructions.When running the chatbot with Docker Compose or Kubernetes, no additional setup is required for PostgreSQL as it is included in the configurations.InstallationTo install the package, you can usepip:pipinstallchatiqStandalone ServerAfter installing thechatiqpackage, you can start the server by running:chatiqBy default, the server listens on port 3000. To specify a different port, use the-por--portoption:chatiq--port4000To configure the server, you can set various environment variables. A complete list of available environment variables and their default values can be found in the.env.examplefile.Integration with FlaskChatIQ can be integrated withFlask. Below are examples of how to set up a simple ChatIQ server with Flask.First, install Flask and an ASGI server likeGunicorn:pipinstallgunicornCreate a file namedapp.pywith the following content:fromflaskimportFlask,make_response,requestfromslack_boltimportBoltRequestfromslack_bolt.adapter.flaskimportSlackRequestHandlerfromchatiqimportChatIQ# Initialize ChatIQ with your settingschatiq=ChatIQ(slack_client_id="your-slack-client-id",# Optional, or read SLACK_CLIENT_ID from environment variablesslack_client_secret="your-slack-client-secret",# Optional, or read SLACK_CLIENT_SECRET from environment variablesslack_signing_secret="your-slack-signing-secret",# Optional, or read SLACK_SIGNING_SECRET from environment variablesopenai_api_key="your-openai-api-key",# Optional, or read OPENAI_API_KEY from environment variablespostgres_url="your-postgres-url",# Optional, or read POSTGRES_URL from environment variablesweaviate_url="your-weaviate-url",# Optional, or read WEAVIATE_URL from environment variablesrate_limit_retry=True,# Optional. Enable the rate limit retry handler (default is False))# Start listening for Slack eventschatiq.listen()# Create a Flask appapp=Flask(__name__)# Create a SlackRequestHandler with the Bolt app from ChatIQhandler=SlackRequestHandler(chatiq.bolt_app)# Handle installation and OAuth redirect endpoints@app.route("/slack/install",methods=["GET"])@app.route("/slack/oauth_redirect",methods=["GET"])defoauth_redirect():# Use the SlackRequestHandler to handle these requestsreturnhandler.handle(request)# Handle Slack events@app.route("/slack/events",methods=["POST"])defendpoint():# Get the request body and headersbody=request.get_data().decode("utf-8")headers={k:vfork,vinrequest.headers}# Create a BoltRequest from the request databolt_req=BoltRequest(body=body,headers=headers)# Dispatch the Bolt request in the ChatIQ's Bolt appbolt_resp=chatiq.bolt_app.dispatch(bolt_req)# Return the response from the Bolt appreturnmake_response(bolt_resp.body,bolt_resp.status,bolt_resp.headers)Run the Flask app with Gunicorn:gunicornapp:appIntegration with Existing Bolt AppsIn addition to integrating with web frameworks, ChatIQ can also be plugged into your existingBoltapps. This allows you to add the functionality of ChatIQ to your existing Slack apps. Here's a simple example:fromslack_boltimportAppfromchatiqimportChatIQ# Assume that you have an existing Bolt appbolt_app=App(...)# Initialize ChatIQ with the existing Bolt appchatiq=ChatIQ(bolt_app=bolt_app,openai_api_key="your-openai-api-key",# Optional, or read OPENAI_API_KEY from environment variablespostgres_url="your-postgres-url",# Optional, or read POSTGRES_URL from environment variablesweaviate_url="your-weaviate-url",# Optional, or read WEAVIATE_URL from environment variablesrate_limit_retry=True,# Optional. Enable the rate limit retry handler (default is False))# Start listening for Slack eventschatiq.listen()Please note that if the same event is registered multiple times in a Bolt app, all the handlers will execute in the order they were registered. Therefore, the event handlers of ChatIQ will be added after your existing handlers. If your existing Bolt app has settings that conflict with ChatIQ, it might cause unexpected behaviors.DevelopmentThere are two ways to set up the development environment: manually or using Visual Studio Code and theDev Containers.Manual SetupClone the repository:gitclonehttps://github.com/yujiosaka/ChatIQ.gitNavigate to the project directory:cdchatiqInstallpoetry:pipinstallpoetryRun thesetup_dev_env.shscript to set up your development environment:./setup_dev_env.shSet the required environment variables in a.envfile.Run the chatbot:flask--appchatiq.main:app--debugrunDocker Dev Container SetupUsing Visual Studio Code and theDev Containersextension, you can simplify the development environment setup process. The extension allows you to develop inside a Docker container and automatically sets up the development environment for you.Install theDev Containersextension in Visual Studio Code.Clone the repository:gitclonehttps://github.com/yujiosaka/ChatIQ.gitOpen the cloned repository in Visual Studio Code.When prompted by Visual Studio Code, click "Reopen in Container" to open the project inside the Docker container.The extension will build the Docker container and set up the development environment for you. This may take a few minutes.Set the required environment variables in a.envfile.Build and run the Docker container with Docker Compose:docker-composeup--buildLocal DeploymentTo deploy the services locally, follow the steps below:Set up the repositoryClone the repository:gitclonehttps://github.com/yujiosaka/ChatIQ.gitNavigate to the project directory:cdchatiqSecrets and ConfigMapsBefore deploying the services, you need to set up Kubernetes Secrets and ConfigMaps.Create a.envfile from the.env.examplefile and fill it with your actual values.Use the following command to create Kubernetes Secrets:makecreate-secretsFor ConfigMaps, use the following command:makecreate-configmapBy default, the ConfigMap will be created with theLOG_LEVELvalue set toinfo. If you want to use a different value, you can specify it as an argument:makecreate-configmapLOG_LEVEL=debugDeploying to KubernetesTo deploy the services to Kubernetes, use the following command:makedeployThis command applies all Kubernetes configuration files located in the./kubernetes/directory.Make sure you have a compatible version of Kubernetes running. The project has been tested and verified with Kubernetes version1.25.4. You can check your Kubernetes version using the following command:kubectlversionAccessing ServicesTo access the deployed services, use the following command to get the list of services and their corresponding URLs:kubectlgetservicesTo check the availability of the service, you can access the health check endpoint athttp://localhost:3000/healthcheck.Cleaning UpTo delete all the deployed resources, use the following command:makedeleteNote: Make sure you havekubectlconfigured to communicate with your Kubernetes cluster.Docker Hub RepositoryDocker images for this project are available in theDocker Hub repository. You can find suitable images for different versions or tags of the ChatIQ application.ConfigurationTo configure and install ChatIQ in your Slack workspace, follow the steps below:Create a new app from the manifestGo to Slack'sYour Appspage and click on "Create an App".Select "From an app manifest" as the creation method.Choose the workspace where you want to install the app and click the "Next" button.Copy the contents of themanifest.yamlfile and paste it into the text field. Then click the "Next" button.Review the app details and click "Create" to create the app.Modify the URLsBefore installing the app, you need to modify the URLs in Slack's app settings:In the "Event Subscriptions" section, update the "Request URL" field by replacingexample.comwith your app's domain.In the "OAuth & Permissions" section, update the "Redirect URLs" by replacingexample.comwith your app's domain.In the "Interactivity & Shortcuts" section, update the "Request URL" field by replacingexample.comwith your app's domain.(Optional) Upload the app iconTo add an app icon, go to the "Display Information" section in the Basic Information settings. Click the "+ Add App Icon" button and upload the desired icon image. You can usethis iconfor the ChatIQ app.Updating App CredentialsBefore starting the application, you need to update the.envfile with the required credentials. Follow the steps below:Create a.envfile from the.env.examplefile.Retrieve the "Client ID", "Client Secret", and "Signing Secret" from the "App Credentials" section in the "Basic Settings" menu of your Slack app.Replace the placeholders in the.envfile with your actual credentials. Make sure to update theOPENAI_API_KEYwith your own OpenAI API Key as well.Save the.envfile.(Re)start the application.Install the app to your workspaceOpen the following URL in your web browser:https://<your-domain>/slack/installClick the "Add to Slack" button.Grant the necessary permissions to the app by clicking "Allow".That's it! The ChatIQ Slack app is now installed in your workspace.Building and PublishingTo build the project, use thepoetry buildcommand:poetrybuildTo upload the built package to PyPI, usepoetry publishcommand:poetrypublishLinting and FormattingThis project usesflake8for linting,blackfor code formatting,isortfor organizing imports, andpytypefor type checking.To lint the code, run:flake8To format the code, run:black.To organize imports, run:isort.To perform type checking with pytype, run:pytypechatiqLimitations and ConsiderationsText Length and Token LimitationOpenAI language models have inherent token limitations. For example, the GPT-3.5-turbo model, currently supported by ChatIQ, has a maximum limit of 4096 tokens. As a result, very long messages might exceed this token limit and cannot be processed.To circumvent this issue, ChatIQ truncates messages to a limit of 3000 tokens. The token limit of 3000 (instead of the maximum 4096) has been chosen to allow room for the wrapping prompt and the inclusion of relevant information from long-term memory in the vectorstore.Please note that this token limit is set based on the chosen language model and may vary if a different model is selected. The ability to select a different model for each team/workspace will be provided in future updates, enabling you to adjust this token limit according to your specific needs and the capabilities of the chosen model.Considerations for CJK CharactersWhen using languages with CJK (Chinese, Japanese, and Korean) characters, note that these languages may consume tokens at a higher rate compared to others for the same number of characters due to the way the tokenizer processes these scripts. This may result in a message hitting the token limit with fewer characters than expected. Always consider the token consumption of your chosen language when interacting with the bot.FAQ1. How is ChatIQ different from ChatGPT?The main difference between ChatIQ and ChatGPT is that the responses generated by ChatIQ are not private and can be shared with others. While ChatGPT provides individual users with private responses, ChatIQ integrates with Slack, enabling team collaboration and knowledge sharing. It allows team members to benefit from the useful responses generated by GPT and facilitates sharing information within the workspace.Additionally, ChatIQ has the capability to read and analyze conversations, including uploaded files, whereas ChatGPT cannot access internal information like sales decks and documents. This feature of ChatIQ enhances its usefulness for business purposes.2. How is ChatIQ different from the ChatGPT app in Slack?TheChatGPT app for Slackis still in beta and its features may change over time. From what is currently known, the ChatGPT app in Slack offers specific functionalities such as providing summarization of threads and assisting in drafting replies to messages. It also aims to enhance the search experience within Slack.On the other hand, ChatIQ provides more flexibility in its use cases. It allows you to use ChatGPT directly within Slack, similar to the ChatGPT app, but with the added advantage of being able to share the generated responses with others. ChatIQ serves as a versatile Slack bot that can be utilized for a wide range of tasks, making it a valuable tool for team collaboration and knowledge sharing.3. What are the security and privacy concerns with ChatIQ?It is important to be aware that when using ChatIQ, the conversation is sent to OpenAI for processing. OpenAI'sTerms of useexplicitly state that the content provided via their API will not be used to develop or improve their services. You can refer to OpenAI's TOS for more details on their data usage policy.Furthermore, ChatIQ stores past conversations and uploaded files in Vectorstore. The decision to make ChatIQ an open-source tool was made to ensure that users have control over their data and do not need to store sensitive information externally. However, it is still advised to exercise caution when inviting the bot to highly sensitive channels, as conversations in those channels will be stored. It is recommended to avoid sharing confidential or sensitive information in channels where the bot is invited.TipsDebuggingIf you're encountering issues with the chatbot, you can modify the log level by setting the corresponding environment variables.To modify the log level, you can pass theLOG_LEVELenvironment variable when running the services with Docker Compose:LOG_LEVEL=debugdocker-composeupThis will override the default log level and set it todebug. You can replacedebugwith any desired log level.TracingIf you want to trace the LangChain runs by the chatbot, you can use LangChain server, which is already configured with Docker Compose. After runningdocker compose up, you can accesshttp://localhost:4173/to see the traced chains.LicenseThis project is licensed under the GPLv3 License. SeeLICENSEfor details.