microsoft / teams-ai

SDK focused on building AI based applications and extensions for Microsoft Teams and other Bot Framework channels
MIT License
404 stars 176 forks source link

[Bug]: Installing AdaptiveCards.Templating package causes PromptManager to miss Prompts folder #1928

Closed donatas-xyz closed 1 month ago

donatas-xyz commented 1 month ago

Language

C#

Version

1.5.0

Description

Installing AdaptiveCards.Templating 2.8.2 NuGet package, that has following dependencies
image

for .Net Core 8 Teams App (created via MS Teams Toolkit), causes PromptManager

PromptManager prompts = new(new()
{
    PromptFolder = "./Prompts"
});

to "miss" Prompts folder load with an error:

The bot encountered an unhandled error: Microsoft.Teams.AI.Exceptions.TeamsAIException: 
Error while loading prompt. 
Method not found: '!!0 Json.More.JsonSerializerOptionsExtensions.Read(System.Text.Json.JsonSerializerOptions, System.Text.Json.Utf8JsonReader ByRef)'. at Microsoft.Teams.AI.AI.Prompts.PromptManager._LoadPromptTemplateFromFile(String name) at Microsoft.Teams.AI.AI.Prompts.PromptManager.GetPrompt(String name) at Program.<>c__DisplayClass0_1.<<$>b__13>d.MoveNext() in C:\path\Program.cs

Uninstalling AdaptiveCards.Templating package resolves the issue.

I'm migrating JS Teams bot to C# one and perhaps I should be using something other than AdaptiveCardTemplate to populate JSON cards?

UPDATE 1: Just tried installing AdaptiveCards.Templating package again, and as expected - the error comes back, when testing locally via Bot Framework Emulator. Uninstalling the package fixes the bot locally. However, no matter what I do - I cannot get rid of this error when testing the bot deployed to Azure via Teams?

UPDATE 2: After whole day's of trial and error, I've narrowed the issue down to actions.json and config.json. This is with the AdaptiveCards.Templating package being uninstalled, which still somehow managed to wreck my Azure deployments, but works locally via Bot Framework Emulator.

The issue is twofold:

  1. actions.json: adding anything more than name and description causes the Method not found: '!!0 Json.More.JsonSerializerOptionsExtensions.Read(System.Text.Json.JsonSerializerOptions, System.Text.Json.Utf8JsonReader ByRef) error.
  2. config.json: adding augmentation section causes the following error:
    System.Exception: Could not load type 'Json.More.JsonNull' from assembly 'Json.More, Version=2.0.0.0, Culture=neutral, PublicKeyToken=17ed63f672b0e278'. at Microsoft.Teams.AI.AI.Planners.ActionPlannerContinueTaskAsync

Once again - none of it happens whilst testing via Bot Framework Emulator.

All 3 files config.json, actions.json and skprompt.txt were working fine before installing AdaptiveCards.Templating.

Reproduction Steps

1. Create an AI ChatBot app with Teams Toolkit 
4. Test if the default prompt loads 
2. Install AdaptiveCards.Templating NuGet package from Microsoft
5. As long as you have `PromptManager` code above - that should not load the prompt anymore 

I haven't tested it with a fresh application. 
I've tried full paths etc to no avail.
donatas-xyz commented 1 month ago

The solution was to install JsonSchema.Net package. The JsonSchema.Net package already comes as part of Microsoft.Teams.AI package and it has Json.More.Net within it, but perhaps that got corrupted somehow beyond repair after I've tried to install AdaptiveCards.Templating package.

So in the end, I've installed JsonSchema.Net, Json.More.Net and Newtonsoft.Json to the packages that already came preloaded with Teams.AI.

The complete list of packages at the moment:

  <ItemGroup>
    <PackageReference Include="AdaptiveCards.Templating" Version="2.0.2" />
    <PackageReference Include="Json.More.Net" Version="2.0.2" />
    <PackageReference Include="JsonSchema.Net" Version="7.2.1" />
    <PackageReference Include="Microsoft.Bot.Builder" Version="4.22.7" />
    <PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.22.7" />
    <PackageReference Include="Microsoft.Graph" Version="5.56.0" />
    <PackageReference Include="Microsoft.Identity.Web.TokenCache" Version="3.0.1" />
    <PackageReference Include="Microsoft.Teams.AI" Version="1.5.*" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
  </ItemGroup>