OfficeDev / teams-toolkit

Developer tools for building Teams apps
Other
471 stars 195 forks source link

Teams Toolkit does not deploy bot using TeamsAI Library correctly #12132

Closed anishgurjar closed 3 months ago

anishgurjar commented 4 months ago

Describe the bug Hi. This issue is targeted to both Teams Toolkit team and Teams AI team since I am not sure which team is responsible for this.

I am trying to chat over my data using Azure OpenAI and have that as a teams bot. Last week, the deploy to Teams feature was created mentioned here: https://techcommunity.microsoft.com/t5/ai-azure-ai-services-blog/announcing-deploy-to-teams-from-azure-openai-studio/ba-p/4198388

The article goes into great detail about how to debug in local environment, which works perfectly fine on my local environment too. I'm able to chat over my data, get citations, have the feedback loop, and all the fancy features.

The article however provides no guidance on deploying this to cloud. I followed Teams Toolkit guidelines to provision, deploy and publish the app. I also validated the app. No errors in any of the stages.

However, when I preview the app on remote environment in Teams using dev.teams.microsoft.com portal, I always get "Bot encountered an error. Check source code". There is almost no doucmentation that I could find on how to exactly log those errors on application insights.

I am wondering if someone has ever tried deploying the actual TeamsAI library to a remote environment instead of merely debugging it in local environment.

To Reproduce Steps to reproduce the behavior:

  1. Go to oai.azure.com
  2. Follow https://techcommunity.microsoft.com/t5/ai-azure-ai-services-blog/announcing-deploy-to-teams-from-azure-openai-studio/ba-p/4198388 article. It's basically having an Azure AI search resource and uploading documents to perform RAG.
  3. Validate the app, provision the app, and then deploy the app.
  4. Visit https://dev.teams.microsoft.com/home and preview the app in teams.

What I have tried to troubleshoot:

  1. Double checked that I have cognitive services openAI user role and the app service has Cognitive Services OpenAI User role assignment as suggested in the article and the readme.
  2. Made sure to verify that provision and deploy happened successfully, and resources were properly created in Azure.

Any help, from either of the teams is appreciated.

therealjohn commented 3 months ago

@anishgurjar Yes, me and several others tested deploying this locally and in Azure.

Step 4 isn't necessary - you should be able to open the preview directly from Teams Toolkit in VS Code or from the CLI.

If you're seeing that error message in the chat, its coming from here: https://github.com/microsoft/teams-ai/blob/main/js/samples/04.ai-apps/h.datasource-azureOpenAI/src/app.ts#L77-L101

In the Azure Portal, go to the App Service that was provisioned to host the node application. Select the Log Stream under the Monitoring section. When that is connected, reproduce the issue in Teams with your bot and you may see more debug information logged to the Log Stream.

Let me know what you find, or if you want to connect via a Teams call and debug it together, I can do that too.

anishgurjar commented 3 months ago

Hi @therealjohn , Thanks for the response! I was able to see the error using the Log Stream. I get a Request failed with status code 401 error. I'm not sure why that is the case, since the bot seems to work fine on my local environment. I appreciate you being open to doing a Teams call - I would love that! What's a good time for the call? I can do it anytime.

therealjohn commented 3 months ago

Hi @therealjohn , Thanks for the response! I was able to see the error using the Log Stream. I get a Request failed with status code 401 error. I'm not sure why that is the case, since the bot seems to work fine on my local environment. I appreciate you being open to doing a Teams call - I would love that! What's a good time for the call? I can do it anytime.

I messaged you on LinkedIn with a way to connect with me. Thanks!

therealjohn commented 3 months ago

The issue was the User Assigned Managed Identity did not have the role assignment. The steps to resolve it were:

  1. Go to the App Service
  2. Select the Identity menu
  3. Remove the System assigned identity settings - that isn't used for you with API Keys.
  4. Select the User assigned tab
  5. Select that identity resource
  6. Select the Azure role assignments
  7. Give that identity the Cognitive Services OpenAI User role
  8. Wait for a few minutes until that takes affect
  9. Try again