It’s the new kid on the block and you can’t stop its rise to fame and the hype train! ChatGPT has generated a lot of attention lately, both positive and negative and it’s already being used by students and content writers to speed up their own work. It’s a buzzword that has been echoed as much as “cloud” was a few years ago (*puke*). And today we are going to learn how we can integrate and use the OpenAI API in Teams by building a Power Automate flow. You know… Just in case you can’t get enough of it in LinkedIn, let’s make it even more available into your own environment… 😂
Our goals:
- Learn how you can easily setup your OpenAI API account.
- Learn the basic requirements to send a request to OpenAI API and work with the responses you get back.
- Learn how to create an integration between OpenAI GPT2-service and a dedicated channel in Microsoft Teams by leveraging Power Automate’s Teams-connector.
Prerequisites:
- An OpenAI API account registered from – OpenAI API
- Power Automate Premium license to use HTTP actions.
- An active Office 365 account with access to create new/existing Teams channels
Create a new dedicated Teams channel (as administrator/owner)
Create your OpenAI API account and token secret
Navigate to https://openai.com/api and create a new account by signing up, if you haven’t done so.
After registration, you need to verify your mail-account in which they will send you a verification in your mailbox. On your first login, you’ll be prompted to provide your personal details and phone no.
Create the Power Automate flow for integration to a Teams channel
URI:
https://api-openai.com/v1/completions
Headers:
Authorization: Bearer {token secret}
Body:
{
"model": "text-davinci-003",
"prompt": "@{triggerOutputs()?['body/body']}",
"max_tokens": 2048,
"temperature": 0.5
}
A few explanations and context for our body:
- model: Read more about model value here – Models – OpenAI API – short version: The higher the performance models are the more expensive. You can also list the available models to try out through its own HTTP request: GET https://api.openai.com/v1/models
- max_tokens: Read more about max_tokens value here – What are tokens and how to count them? | OpenAI Help Center – short version: token represents a number count of either words or sentences. The limit is counting both the prompt (your question) + completion (the text result returned) < 4000 (as long as it’s below 4000 token counts together)
- temperature: Read more about temperature combinations here – API Reference – OpenAI API – A measure of how often the model outputs a less likely text/token. The higher the temperature, the more random (and usually creative) the output. This, however, is not the same as “truthfulness”. For most factual use cases such as data extraction, and truthful Q&A, the temperature of 0 is best.
Now save and trigger the flow once from your Teams channel (ask about anything) and wait for a response, as we want to parse the JSON values from the returning body.
Paste in the copied value and click done.
You can now save your flow one last time, as this is all that is required for this example, and you can use your Teams channels for text-based responses from OpenAI/ChatGPT. Remember, it does support multiple languages (if not all).
Summary
We’ve learned how to create an integration between ChatGPT/OpenAI and Microsoft Teams, by leveraging the Power Automate tool.
The flow result:
While this is a simple flow, Power Platform’s services and its ecosystem of connectors can be added to build more complex automation (E.g. Power Virtual Agents), depending on your project goals. This is just an example of how the OpenAI API can be used together with Azure and Microsoft 365 services – and even combine with other public facing APIs. Unfortunately, Microsoft Teams connector in this tutorial doesn’t have the most responsive triggers as it only scans new messages every 3 minutes. Because of this limit I sometimes ask in bulks and sips on my cup of tea while waiting… I could however replaced it’s trigger with “When keywords are mentioned“… But it will do just fine for me – for now! 😎
Leave a Reply