You already use ChatGPT in the browser, but how do you incorporate the technology into your own product?
This code lab will walk you through all the steps to create a Google Chat bot that is powered by ChatGPT and fully customizable to your desires.
- Google Workspace account with Google Chat enabled.
- Google Cloud account, with billing enabled, or free trial.
- OpenAI account, with billing enabled, or free trial credits.
- Experience with Python.
By the end of the code lab you will have learned:
- How to set up and configure a Google Chat bot
- How to set up a Google Cloud Function and trigger it from Google Chat
- How to protect your bot's code from unauthorized traffic
- How to use the Chat and Image APIs from OpenAI to make your bot brilliant
- How to use slash commands to give your bot specific skills
- How to use Google Cloud Datastore to track a history of messages
- How to create cards and dialogs to improve the UX of your bot
- How to combine everything you've built into a brand new skill for your bot
The lab is split in nine modules that are designed to be completed in order, with each one building on the work from the previous one.
In the first module you'll build a basic chat bot. Each subsequent module will add additional functionality to the bot. At the end of each module you should have a working bot which you can test to verify all the steps were completed successfully.
Each module also contains a repo which is how your code should look after completing all the steps in the module. If you ever get stuck, you can compare your code to the repo code to track down any issues.
As an alternative, you can start at any module and use the repo code from the previous module as the starting point for your project.
-
Module 1 - Build a Basic Chat Bot
Set up and configure a basic bot for Google Chat. -
Module 2 - Add OpenAI
Use ChatGPT to reply to incoming messages. -
Module 3 - Verify Requests
Verify requests before processing messages. -
Module 4 - Add Datastore
Give your bot memory by tracking a history of messages. -
Module 5 - Add Slash Commands
Give your bot special skills with custom commands. -
Module 6 - Add Image Support
Add support for image generation using DALL·E 2. -
Module 7 - Collect API Key
Process messages with each user's OpenAI API key. -
Module 8 - Add a Dialog
Improve the setup experience by using a dialog. -
Module 9 - Interactive Story
Build a "Choose Your Own Adventure" story generator.
This code lab was presented as a workshop for the Google Developer Student Club at the University of Colorado in Boulder.
Google Chat API
- Documentation
- Event Reference
- Event Formats
- Card Reference
- Card Builder
- Text Formatting Reference
- Publish Google Chat apps
OpenAI
Google Cloud
- Cameron Henneke - GQueues
This code lab was built by the makers of GQueues.
This project is licensed under the MIT License - see the LICENSE file for details.