-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
...osoft.TeamsAI.Tests/AITests/PromptsTests/SectionsTests/ActionOutputMessageSectionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using Microsoft.Teams.AI.AI.Models; | ||
using Microsoft.Teams.AI.AI.Prompts.Sections; | ||
using Microsoft.Teams.AI.State; | ||
using Microsoft.Teams.AI.Tests.TestUtils; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Teams.AI.Tests.AITests.PromptsTests.SectionsTests | ||
{ | ||
public class ActionOutputMessageSectionTests | ||
{ | ||
[Fact] | ||
public async Task Test_RenderAsMessages_NoHistory_ReturnsEmptyList() | ||
{ | ||
// Arrange | ||
var historyVariable = "temp.history"; | ||
var turnContext = TurnStateConfig.CreateConfiguredTurnContext(); | ||
var turnState = await TurnStateConfig.GetTurnStateWithConversationStateAsync(turnContext); | ||
turnState.SetValue(historyVariable, new List<ChatMessage>() { }); | ||
turnState.SetValue(TempState.ActionOutputsKey, new Dictionary<string, string>()); | ||
var section = new ActionOutputMessageSection(historyVariable); | ||
|
||
// Act | ||
var sections = await section.RenderAsMessagesAsync(turnContext, turnState, null!, null!, 0); | ||
|
||
// Assert | ||
Assert.Empty(sections.Output); | ||
} | ||
|
||
[Fact] | ||
public async Task Test_RenderAsMessages_HistoryWithoutActionCalls_ReturnsEmptyList() | ||
{ | ||
// Arrange | ||
var historyVariable = "temp.history"; | ||
var turnContext = TurnStateConfig.CreateConfiguredTurnContext(); | ||
var turnState = await TurnStateConfig.GetTurnStateWithConversationStateAsync(turnContext); | ||
turnState.SetValue(historyVariable, new List<ChatMessage>() { new ChatMessage(ChatRole.Assistant) }); | ||
turnState.SetValue(TempState.ActionOutputsKey, new Dictionary<string, string>()); | ||
var section = new ActionOutputMessageSection(historyVariable); | ||
|
||
// Act | ||
var sections = await section.RenderAsMessagesAsync(turnContext, turnState, null!, null!, 0); | ||
|
||
// Assert | ||
Assert.Empty(sections.Output); | ||
} | ||
|
||
[Fact] | ||
public async Task Test_RenderAsMessages_WithActionCalls_AddsToolMessage() | ||
{ | ||
// Arrange | ||
var historyVariable = "temp.history"; | ||
var turnContext = TurnStateConfig.CreateConfiguredTurnContext(); | ||
var turnState = await TurnStateConfig.GetTurnStateWithConversationStateAsync(turnContext); | ||
turnState.SetValue(historyVariable, new List<ChatMessage>() { | ||
new ChatMessage(ChatRole.Assistant) { | ||
ActionCalls = new List<ActionCall> { new ActionCall("testId", new ActionFunction("testName", "{}")) } | ||
} | ||
}); | ||
turnState.SetValue(TempState.ActionOutputsKey, new Dictionary<string, string>() | ||
{ | ||
{ "testId", "testOutput" } | ||
}); | ||
var section = new ActionOutputMessageSection(historyVariable); | ||
|
||
// Act | ||
var sections = await section.RenderAsMessagesAsync(turnContext, turnState, null!, null!, 0); | ||
|
||
// Assert | ||
Assert.Single(sections.Output); | ||
Assert.Equal("testOutput", sections.Output[0].Content); | ||
} | ||
|
||
[Fact] | ||
public async Task Test_RenderAsMessages_WithInvalidActionCalls_AddsToolMessage_WithEmptyOutput() | ||
{ | ||
// Arrange | ||
var historyVariable = "temp.history"; | ||
var turnContext = TurnStateConfig.CreateConfiguredTurnContext(); | ||
var turnState = await TurnStateConfig.GetTurnStateWithConversationStateAsync(turnContext); | ||
turnState.SetValue(historyVariable, new List<ChatMessage>() { | ||
new ChatMessage(ChatRole.Assistant) { | ||
ActionCalls = new List<ActionCall> { new ActionCall("testId", new ActionFunction("testName", "{}")) } | ||
} | ||
}); | ||
turnState.SetValue(TempState.ActionOutputsKey, new Dictionary<string, string>() | ||
{ | ||
{ "InvalidTestId", "testOutput" } | ||
}); | ||
var section = new ActionOutputMessageSection(historyVariable); | ||
|
||
// Act | ||
var sections = await section.RenderAsMessagesAsync(turnContext, turnState, null!, null!, 0); | ||
|
||
// Assert | ||
Assert.Empty(sections.Output); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters