Integrate Azure Open AI in Teams Channel via Logic App
Published Mar 22 2023 11:48 PM 23.5K Views
Microsoft

Summary

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.

 

Prerequisite

  1. Azure Open AI resource with a deployment which using "chatgpt-35-turbo".Drac_Zhang_1-1679541391775.png
     
  2. 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.Drac_Zhang_0-1679541908390.png
     
  3. Prepare Teams channel ID and group ID in advance, you can get them via right on Channel and select "Get link to channel".  Drac_Zhang_0-1679542433205.png 
    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.Drac_Zhang_1-1679542829781.png

Mechanism

  1. 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.
  2. 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.
  3. Compose the content as Open AI payload and send request, transfer the response to specific Teams channel.
  4. 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:

Parameter Name Comments
openai_apikey The api key of Open AI resource, it can be found in Open AI -> Keys and Endpoints
openai_endpoint

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

teams_channel_keyword The keywords you would like to trigger the Logic App, not case sensitive
teams_channel_id See prerequisite No.3
teams_group_id See prerequisite No.3
storage_account_name The storage account name for saving conversation history
storage_account_accesskey The access key for the storage account

 

Known Issues

  1. After the deployment, the Teams API connector need to be authorize manually.
  2. Logic App need to be disable and re-enable for registering the webhook on Teams side
  3. If the response from Open AI contains the keywords, then the Logic App will be trigger again
  4. 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

Sample Chat

Drac_Zhang_0-1679549656048.png

 

Reference

How to work with the ChatGPT and GPT-4 models (preview) - Azure OpenAI Service | Microsoft Learn

 

9 Comments
Co-Authors
Version history
Last update:
‎May 16 2023 06:15 PM
Updated by: