Work without ChatGPT?
It has simply become unthinkable. ChatGPT has long evolved into the superhero of productivity tools. Even right now, as I type, it helps me come up with cooler phrases. To your luck!
Yet, the data dilemma lurks. It is no secret that ChatGPT stores each and every prompt sent to it. Yes, even the most embarrassing ones… Some companies play it cool, letting employees ChatGPT away with rules like »anonimize the input« or »exclude sensitive data«. Others drop the banhammer entirely.
We, at &, do things differently.
Curious about how we did it?
In an initial step, we planned out the architecture. Our focus was clear: Select technologies which play well with both Google Chat and Azure OpenAI Service.
We also took into consideration existing libraries. On the one hand, the Google API Client Libraries. They help develop for Google Chat and are available for Dart, Go, Java, JavaScript, Node.js, Objective-C, PHP, Python, Ruby, and .NET. On the other hand, the Azure OpenAI Client Libraries. They facilitate communication with OpenAI models from Azure OpenAi Service and are available for C#, Go, Java, JavaScript, and Python.
Before we delve into the details, let’s clarify some Google terms. First up is »Google Workspace«, formerly known as »GS Suite«. It is a collection of cloud-based business solutions including Google Chat, Google Drive, Google Calendar, etc. Collectively, we refer to them as »Google Workspace apps«.
Google Workspace add-ons can be downloaded from the Google Workspace Marketplace. Google Chat apps can be, additionally, installed from inside Google Chat.
Last but not least, the predecessor of Google Chat was called »Google Hangouts«. So you may still find traces of it. For example, as comments inside libraries or as code in outdated tutorials.
At this point, we have a clear idea of what we are building (a web service), what to call it (a Google Chat app), and which framework, language, and libraries to use (Spring Boot, Java, Google Chat API Client Library for Java, Azure OpenAI Client Library for Java).
However, we still need to code everything.
Google Chat apps, implemented as web services, have one thing in common. They expose a singular HTTP endpoint. This endpoint will receive POST requests when users interact with our Google Chat app. Each POST request contains an Event object as its request body. Depending on the occasion, this event can have one of three types. Namely, ADDED_TO_SPACE, MESSAGE, or REMOVED_FROM_SPACE.
To respond, our endpoint simply sends back a Message object. Our response will then be displayed in the corresponding conversation inside Google Chat. We do not have to handle this ourselves. There is just one exception. When replying to REMOVED_FROM_SPACE events, our response is simply ignored. However, by then, the user has already left the space, anyways.
There is just one last thing to remember: Google Chat only gives us 30 seconds to respond. Otherwise, a timeout will occur and a disappointed user will be greeted with the error message »[app name] not responding« inside Google Chat.
See a sample endpoint below. The Google API Client Library for Java provides us with the Message object.
As of now, our responses are as boring as »Event type was ADDED_TO_SPACE«. We want more. We want our responses to be generated by our own instance of OpenAI’s ChatGPT model.
Azure offers us REST API access to GPT-3.5 and GPT-4. We simply need an Azure Subscription with access to Azure OpenAI. Deploying our own instance of the ChatGPT model is as easy as filling in fields and clicking on buttons. Here is a guide by Azure!
As mentioned above, the Azure OpenAI Client Library for Java is worth looking at. It helps us connect our Spring Boot app with Azure OpenAI Service. Personally, we wrote a service, OpenAiClient, which uses this library to communicate with our OpenAI model.
Now, we only need to make a few changes to make our responses sound much smarter…
Our code is complete! There are only two more things left to do:
(1) Deploy our Spring Boot app.
(2) Create a Google Cloud project.
For deployment, we used Azure’s Web App Service.
The Google Cloud project is our link to Google Chat. It is what transforms our Spring Boot app into a Google Chat app. Inside the configurations, we simply need to enable the Google Chat API. Inside the Google Chat API configurations, we can then paste the address to our endpoint. Here is a guide by Google.
And with that, we officially created a Google Chat app!
During development, you can configure a maximum of five test users. You will find the option in the configurations for the Google Chat API. The selected few will now find our Google Chat app among the others inside Google Workspace Marketplace or Google Chat. They can use it right away!
If you want to publish, you need to enable the Google Marketplace API. In the Google Marketplace API configurations, you can then determine a scope of access fitting to your purpose. Personally, we restricted access to our Google Workspace organisation.
When moving forward, there are some aspects you might want to consider:
We, at &, are building various applications — from chatbots to enterprise cloud applications. If you want to work with us or have any questions about how we built ampGPT in more detail, get in touch!