Skip to content

Commit

Permalink
[C#] fix: failure to load prompt due to json serialization error (#2227)
Browse files Browse the repository at this point in the history
## Linked issues

closes: #minor (issue number)

## Details
- Bumping `JsonSchema` to v6.1.2 so that it uses `Json.More.Net` version
2.x
- Fixed a test failure in a previous PR (.net build was not run)

#### Change details
_Exception_
```
Microsoft.Teams.AI.Exceptions.TeamsAIException: Error while loading prompt. Method not found: \u0027!!0 Json.More.JsonSerializerOptionsExtensions.Read(System.Text.Json.JsonSerializerOptions, System.Text.Json.Utf8JsonReader ByRef)\u0027.\r\n   at Microsoft.Teams.AI.AI.Prompts.PromptManager._LoadPromptTemplateFromFile(String name)\r\n   at Microsoft.Teams.AI.AI.Prompts.PromptManager.GetPrompt(String name)\r\n   at Program.\u003C\u003Ec__DisplayClass0_1.\u003C\u003C\u003CMain\u003E$\u003Eb__14\u003Ed.MoveNext() in C:\\TFS\\Icertis.AI.M365Copilot\\Icertis.AI.M365Copilot.App\\Program.cs:line 148\r\n--- End of stack trace from previous location ---\r\n   at Microsoft.Teams.AI.AI.Planners.ActionPlanner\u00601.ContinueTaskAsync(ITurnContext context, TState state, AI\u00601 ai, CancellationToken cancellationToken)\r\n   at Microsoft.Teams.AI.AI.Planners.ActionPlanner\u00601.BeginTaskAsync(ITurnContext context, TState state, AI\u00601 ai, CancellationToken cancellationToken)\r\n   at Microsoft.Teams.AI.AI.AI\u00601.RunAsync(ITurnContext turnContext, TState turnState, Nullable\u00601 startTime, Int32 stepCount, CancellationToken cancellationToken)\r\n   at Microsoft.Teams.AI.Application\u00601._OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken)\r\n   at Microsoft.Teams.AI.Application\u00601.OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken)\r\n   at Microsoft.Teams.AI.Application.Authentication.Bot.FilteredTeamsSSOTokenExchangeMiddleware.OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.MiddlewareSet.ReceiveActivityWithStatusAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken)\r\n   at Microsoft.Bot.Builder.BotAdapter.RunPipelineAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken)
```

## Attestation Checklist

- [x] My code follows the style guidelines of this project

- I have checked for/fixed spelling, linting, and other errors
- I have commented my code for clarity
- I have made corresponding changes to the documentation (updating the
doc strings in the code is sufficient)
- My changes generate no new warnings
- I have added tests that validates my changes, and provides sufficient
test coverage. I have tested with:
  - Local testing
  - E2E testing in Teams
- New and existing unit tests pass locally with my changes
  • Loading branch information
singhk97 authored Dec 10, 2024
1 parent 2ba12e3 commit bc4c3a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ public async Task Test_CompletePromptAsync_PromptResponse_NotSuccess()
LLMClientOptions<object> options = new(promptCompletionModel, promptTemplate) { MaxHistoryMessages = 1 };
LLMClient<object> client = new(options, null);
TestMemory memory = new();
ChatMessage message = new ChatMessage("Hi there");
promptCompletionModel.Results.Enqueue(new()
{
Input = new List<ChatMessage>() { message },
Status = PromptResponseStatus.Error,
Error = new TeamsAIException("test")
});
Expand All @@ -113,7 +115,10 @@ public async Task Test_CompletePromptAsync_PromptResponse_NotSuccess()
Assert.Equal(PromptResponseStatus.Error, response.Status);
Assert.NotNull(response.Error);
Assert.Equal("test", response.Error.Message);
Assert.Empty(memory.Values);
Assert.Single(memory.Values);

IList<ChatMessage> conversation_history = (IList<ChatMessage>)memory.GetValue("conversation.history")!;
Assert.True(conversation_history[0].Content == message.Content);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<PackageReference Include="AdaptiveCards" Version="3.1.0" />
<PackageReference Include="Azure.AI.ContentSafety" Version="1.0.0" />
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0-beta.1" />
<PackageReference Include="JsonSchema.Net" Version="5.5.1" />
<PackageReference Include="JsonSchema.Net" Version="6.1.2" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.22.9" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.22.9" />
Expand Down

0 comments on commit bc4c3a5

Please sign in to comment.