Sunday, 26 November 2023

Manage Azure OpenAI Service using the Azure CLI

I was working on a project recently where we were using the Azure OpenAI service quite heavily. As part of creating the DevOps pipelines for the project, we had to look into automating the management of the Azure OpenAI service. Turns out this functionality is possible with the Azure CLI however it is available under the Cognitive Services module which can be a bit tricky to find. So here is a quick blog post detailing some of the more frequently used operations for the Azure OpenAI service through the Azure CLI:

#Create Azure OpenAI service instance
az cognitiveservices account create --name azurecliopenaiservice --resource-group myresourcegroup --kind OpenAI --sku S0 --location uksouth --yes
#Create deployment of gpt-35-turbo-16k
az cognitiveservices account deployment create --name azurecliopenaiservice --resource-group myresourcegroup --model-format OpenAI --model-name gpt-35-turbo-16k --model-version 0613 --deployment-name gpt-35-turbo-16k --sku-name "Standard" --capacity 120
#Get Azure OpenAI service engpoint
az cognitiveservices account show --name azurecliopenaiservice --resource-group myresourcegroup --query properties.endpoint
#Get Azure OpenAI service primary key
az cognitiveservices account keys list --name azurecliopenaiservice --resource-group myresourcegroup --query key1
#Delete an Azure OpenAI service instance
az cognitiveservices account delete --name azurecliopenaiservice --resource-group myresourcegroup
#Delete deployment with name gpt-35-turbo-16k
az cognitiveservices account deployment delete --name azurecliopenaiservice --resource-group myresourcegroup --deployment-name gpt-35-16k

For a full set of operations, please see the Microsoft docs: https://learn.microsoft.com/en-us/cli/azure/cognitiveservices?view=azure-cli-latest

Thursday, 16 November 2023

Teams tab fails to load in the new Microsoft Teams Desktop client

The new Microsoft Teams Desktop client was made generally available for Windows and Mac recently. The good news is that the new client provides feature parity for 3rd party apps like Focusworks AI giving customers a choice of using their preferred Teams client to access the apps.

However, if you have a custom built Microsoft Teams tab or a task module as part of your solution, and find that it fails to load in the new Microsoft Teams client, there might be a specific reason for it. 

And since there is no way to invoke the Developer tools in the new Teams desktop client yet (November 2023), the experience can get a bit frustrating. 

In my case, I have a custom React/TypeScript based tab which is using the @microsoft/teams-js library to interact with Teams. 

Since teams tabs are just HTML pages, we need to make sure that the page is being loaded inside Teams before continuing to execute the code. To do that we can use the context.app.host.name property and check that the value was "teams" before moving ahead.

import * as microsoftTeams from "@microsoft/teams-js";
//other code
const context = await microsoftTeams.app.getContext();
if (context?.app?.host?.name === microsoftTeams.HostName.teams) {
//code to execute if app is running in Teams client.
}
view raw TeamsTab.ts hosted with ❤ by GitHub

However, with the new desktop client my tab was failing to load. After a bit of digging around I realised that the new Teams desktop client has an entirely different host name property and the value is "teamsModern" as mentioned here: https://learn.microsoft.com/en-us/javascript/api/%40microsoft/teams-js/hostname?view=msteams-client-js-latest

So changing my code to include the new value as well worked!

if (context?.app?.host?.name === microsoftTeams.HostName.teams ||
context?.app?.host?.name === microsoftTeams.HostName.teamsModern) {
//code to execute if app is running in classic or new Teams client.
}
Hope this saves you some debugging time!