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
- 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.
Mechanism
- 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:
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
- 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
Sample Chat
Reference
How to work with the ChatGPT and GPT-4 models (preview) - Azure OpenAI Service | Microsoft Learn
Updated May 17, 2023
Version 3.0Drac_Zhang
Microsoft
Joined March 08, 2021
Azure Integration Services Blog
Follow this blog board to get notified when there's new activity