Now in Azure, we can deploy Open AI with chatgpt-35-turbo model as an Azure resource, so this blog introduces how to integrate the Azure Open AI in Teams channel without using a bot.
- Azure Open AI resource with a deployment which using "chatgpt-35-turbo".
- Azure Storage Account with a blob container which named "gpt". For Open AI conversion, if we need to enable the multi-turn conversations, we need to provide the whole conversation (channel replies) histories for Open AI API call. But in Logic App, we don't have built-in action for get all the replies of a channel message, so we need to use blob storage to save the conversation history based on message IDs.
- Prepare Teams channel ID and group ID in advance, you can get them via right on Channel and select "Get link to channel".
Once we have the URL, we need to do a URL decode (or just replace %3a as ':' and %40 as '@', otherwise the Logic App cannot get correct channel ID) to get actual channel and Group ID. In the following screenshot, the green section is the channel ID and the red one is the group ID.
- Logic App is monitoring the keywords posted in specific channel via trigger "When keywords are mentioned". In my case, I'm using ChatGPT as keyword, so once the messages/replies contian "ChatGPT", it will trigger Logic App.
- If this is a new message, Logic App will create a new blob for saving conversation history based on message ID (it is ReplyToId in Teams connector response). Otherwise it reads the existing blobs and re-use the conversation.
- Compose the content as Open AI payload and send request, transfer the response to specific Teams channel.
- Update blob with the latest conversation.
Template and Parameters Explanation
The sample template link: Drac-Zhang/LogicApp_For_Teams_OpenAI_Integration (github.com)
Parameters of the template:
||The api key of Open AI resource, it can be found in Open AI -> Keys and Endpoints
Open AI api endpoint, the format is https://[Open AI resource Name].openai.azure.com/openai/deployments/[Deployment name]/chat/completions?api-version=2023-03-15-preview
The version must be 2023-03-15-preview since the previous version is using a different payload JSON schema
||The keywords you would like to trigger the Logic App, not case sensitive
||See prerequisite No.3
||See prerequisite No.3
||The storage account name for saving conversation history
||The access key for the storage account
- After the deployment, the Teams API connector need to be authorize manually.
- Logic App need to be disable and re-enable for registering the webhook on Teams side
- If the response from Open AI contains the keywords, then the Logic App will be trigger again
- If the response contains double quotas, then the next reply will failed due to invalid JSON format, but it can be easily fixed by replace expression
How to work with the ChatGPT and GPT-4 models (preview) - Azure OpenAI Service | Microsoft Learn