Skip to content

Commit

Permalink
[C#] chore: Merge breaking-changes-2 into main (#1029)
Browse files Browse the repository at this point in the history
## Linked issues

closes: #1028

## Details

Merge `breaking-changes-2` onto `main`.

_NOTE:_ the branch is actually `breaking-changes-4`. I tried rebasing
`breaking-changes-2` and accidentally pushed it to remote - so now the
branch is corrupted. Nonetheless this branch reflects that state of
`breaking-changes-2` before the rebase fiasco.

## 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 (we use
[TypeDoc](https://typedoc.org/) to document our code)
- 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

---------

Co-authored-by: Alex Acebo <[email protected]>
Co-authored-by: limamicro <[email protected]>
Co-authored-by: Kuojian Lu <[email protected]>
Co-authored-by: Lily Du <[email protected]>
Co-authored-by: Qianhao Dong <[email protected]>
Co-authored-by: Yunny Chung - MSFT <[email protected]>
Co-authored-by: Yunny Chung <[email protected]>
Co-authored-by: Chaoyi Yuan <[email protected]>
  • Loading branch information
9 people authored Dec 6, 2023
1 parent 58f9879 commit a20f871
Show file tree
Hide file tree
Showing 536 changed files with 23,140 additions and 11,524 deletions.
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
* @microsoft/teams-ai-admins @microsoft/teams-ai-maintainer

# JS
/js @corinagum @Stevenic @aacebo @lilyydu @singhk97
/js @corinagum @aacebo @lilyydu @singhk97

# .NET
/dotnet @singhk97 @swatDong @kuojianlu @lilyydu
/dotnet @singhk97 @swatDong @kuojianlu @lilyydu @corinagum @aacebo

# Python
/python @aacebo @blackchoey @lilyydu @singhk97
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ dist
/dotnet/packages/Microsoft.TeamsAI/.vs
/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/bin
/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/obj
/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/bin
/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/obj
/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/bin/Debug/net6.0
/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/obj/Debug/net6.0
/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/obj
/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/IntegrationTests/testsettings.json
/dotnet/samples/01.echoBot/.vs/*

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Bot.Builder;
using Microsoft.Teams.AI.AI.Action;
using Microsoft.Teams.AI.Tests.TestUtils;
using Microsoft.Teams.AI.State;

namespace Microsoft.Teams.AI.Tests.AITests
{
Expand All @@ -10,15 +10,15 @@ public class ActionCollectionTests
public void Test_Simple()
{
// Arrange
IActionCollection<TestTurnState> actionCollection = new ActionCollection<TestTurnState>();
IActionCollection<TurnState> actionCollection = new ActionCollection<TurnState>();
string name = "action";
IActionHandler<TestTurnState> handler = new TestActionHandler();
IActionHandler<TurnState> handler = new TestActionHandler();
bool allowOverrides = true;

// Act
actionCollection.AddAction(name, handler, allowOverrides);
ActionEntry<TestTurnState> entry = actionCollection[name];
bool tryGet = actionCollection.TryGetAction(name, out ActionEntry<TestTurnState> tryGetEntry);
ActionEntry<TurnState> entry = actionCollection[name];
bool tryGet = actionCollection.TryGetAction(name, out ActionEntry<TurnState> tryGetEntry);

// Assert
Assert.True(actionCollection.ContainsAction(name));
Expand All @@ -37,9 +37,9 @@ public void Test_Simple()
public void Test_Add_NonOverridable_Action_Throws_Exception()
{
// Arrange
IActionCollection<TestTurnState> actionCollection = new ActionCollection<TestTurnState>();
IActionCollection<TurnState> actionCollection = new ActionCollection<TurnState>();
string name = "action";
IActionHandler<TestTurnState> handler = new TestActionHandler();
IActionHandler<TurnState> handler = new TestActionHandler();
bool allowOverrides = false;
actionCollection.AddAction(name, handler, allowOverrides);

Expand All @@ -55,7 +55,7 @@ public void Test_Add_NonOverridable_Action_Throws_Exception()
public void Test_Get_NonExistent_Action()
{
// Arrange
IActionCollection<TestTurnState> actionCollection = new ActionCollection<TestTurnState>();
IActionCollection<TurnState> actionCollection = new ActionCollection<TurnState>();
var nonExistentAction = "non existent action";

// Act
Expand All @@ -70,11 +70,11 @@ public void Test_Get_NonExistent_Action()
public void Test_TryGet_NonExistent_Action()
{
// Arrange
IActionCollection<TestTurnState> actionCollection = new ActionCollection<TestTurnState>();
IActionCollection<TurnState> actionCollection = new ActionCollection<TurnState>();
var nonExistentAction = "non existent action";

// Act
var result = actionCollection.TryGetAction(nonExistentAction, out ActionEntry<TestTurnState> actionEntry);
var result = actionCollection.TryGetAction(nonExistentAction, out ActionEntry<TurnState> actionEntry);

// Assert
Assert.False(result);
Expand All @@ -85,7 +85,7 @@ public void Test_TryGet_NonExistent_Action()
public void Test_ContainsAction_False()
{
// Arrange
IActionCollection<TestTurnState> actionCollection = new ActionCollection<TestTurnState>();
IActionCollection<TurnState> actionCollection = new ActionCollection<TurnState>();
var nonExistentAction = "non existent action";

// Act
Expand All @@ -99,8 +99,8 @@ public void Test_ContainsAction_False()
public void Test_ContainsAction_True()
{
// Arrange
IActionCollection<TestTurnState> actionCollection = new ActionCollection<TestTurnState>();
IActionHandler<TestTurnState> handler = new TestActionHandler();
IActionCollection<TurnState> actionCollection = new ActionCollection<TurnState>();
IActionHandler<TurnState> handler = new TestActionHandler();
var name = "actionName";

// Act
Expand All @@ -111,11 +111,11 @@ public void Test_ContainsAction_True()
Assert.True(containsAction);
}

private sealed class TestActionHandler : IActionHandler<TestTurnState>
private sealed class TestActionHandler : IActionHandler<TurnState>
{
public Task<bool> PerformAction(ITurnContext turnContext, TestTurnState turnState, object? entities = null, string? action = null)
public Task<string> PerformActionAsync(ITurnContext turnContext, TurnState turnState, object? entities = null, string? action = null, CancellationToken cancellationToken = default)
{
return Task.FromResult(true);
return Task.FromResult(string.Empty);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
using Microsoft.Teams.AI.AI;
using Microsoft.Teams.AI.AI.Action;
using Microsoft.Teams.AI.AI.Moderator;
using Microsoft.Teams.AI.AI.Planner;
using Microsoft.Teams.AI.AI.Prompt;
using Microsoft.Teams.AI.AI.Planners;
using Microsoft.Teams.AI.State;
using Microsoft.Teams.AI.Tests.TestUtils;
using Microsoft.Bot.Schema;
Expand All @@ -20,14 +19,14 @@ public void Test_Actions_DifferentReturnTypes()
// Arrange
var instance = new DifferentReturnTypesActions();
var turnContext = new TurnContext(new NotImplementedAdapter(), MessageFactory.Text("hello"));
var turnState = new TestTurnState();
var actionNames = new[] { "action1", "action2", "action3", "action4", "action5", "action6" };
var turnState = new TurnState();
var actionNames = new[] { "action1", "action2", "action3" };

// Act
IActionCollection<TestTurnState> actions = ImportActions<TestTurnState>(instance);
IActionCollection<TurnState> actions = ImportActions<TurnState>(instance);
foreach (var actionName in actionNames)
{
actions[actionName].Handler.PerformAction(turnContext, turnState);
actions[actionName].Handler.PerformActionAsync(turnContext, turnState);
}

// Assert
Expand All @@ -42,17 +41,17 @@ public void Test_Actions_DifferentReturnTypes()
public void Test_Actions_DifferentParameterAttributes()
{
// Arrange
var instance = new DifferentParameterAttributesActions<TestTurnState>();
var instance = new DifferentParameterAttributesActions<TurnState>();
var turnContext = new TurnContext(new NotImplementedAdapter(), MessageFactory.Text("hello"));
var turnState = new TestTurnState();
var turnState = new TurnState();
var actionNames = new[] { "action1", "action2", "action3", "action4", "action5", "action6" };
var entities = new object();

// Act
IActionCollection<TestTurnState> actions = ImportActions<TestTurnState>(instance);
IActionCollection<TurnState> actions = ImportActions<TurnState>(instance);
foreach (var actionName in actionNames)
{
actions[actionName].Handler.PerformAction(turnContext, turnState, entities, actionName);
actions[actionName].Handler.PerformActionAsync(turnContext, turnState, entities, actionName);
}

// Assert
Expand All @@ -78,25 +77,25 @@ public async Task Test_Actions_ParameterAssign_Exception(object instance, Type f
{
// Arrange
var turnContext = new TurnContext(new NotImplementedAdapter(), MessageFactory.Text("hello"));
var turnState = new TestTurnState();
var turnState = new TurnState();
var actionName = "action";
var entities = new object();

// Act
IActionCollection<TestTurnState> actions = ImportActions<TestTurnState>(instance);
var exception = await Assert.ThrowsAsync<InvalidOperationException>(async () => await actions[actionName].Handler.PerformAction(turnContext, turnState, entities, actionName));
IActionCollection<TurnState> actions = ImportActions<TurnState>(instance);
var exception = await Assert.ThrowsAsync<InvalidOperationException>(async () => await actions[actionName].Handler.PerformActionAsync(turnContext, turnState, entities, actionName));

// Assert
Assert.NotNull(exception);
Assert.Equal($"Cannot assign {from} to {to} of action method Action", exception.Message);
}

private static IActionCollection<TState> ImportActions<TState>(object instance) where TState : ITurnState<StateBase, StateBase, TempState>
private static IActionCollection<TState> ImportActions<TState>(object instance) where TState : TurnState
{
AIOptions<TState> options = new(
new Mock<IPlanner<TState>>().Object,
new PromptManager<TState>(),
new Mock<IModerator<TState>>().Object);
AIOptions<TState> options = new(new Mock<IPlanner<TState>>().Object)
{
Moderator = new Mock<IModerator<TState>>().Object
};
AI<TState> ai = new(options);
ai.ImportActions(instance);
// get _actions field from AI class
Expand All @@ -108,25 +107,25 @@ private static IEnumerable<object[]> ParameterAssignTestData()
{
yield return new object[]
{
new TestActions<string, TestTurnState, object, string>(),
new TestActions<string, TurnState, object, string>(),
typeof(TurnContext),
typeof(string),
};
yield return new object[]
{
new TestActions<TurnContext, string, object, string>(),
typeof(TestTurnState),
typeof(TurnState),
typeof(string),
};
yield return new object[]
{
new TestActions<TurnContext, TestTurnState, string, string>(),
new TestActions<TurnContext, TurnState, string, string>(),
typeof(object),
typeof(string),
};
yield return new object[]
{
new TestActions<TurnContext, TestTurnState, object, int>(),
new TestActions<TurnContext, TurnState, object, int>(),
typeof(string),
typeof(int),
};
Expand All @@ -137,92 +136,81 @@ private sealed class DifferentReturnTypesActions
public List<string> Calls { get; set; } = new List<string>();

[Action("action1")]
public void Action1()
public string Action1()
{
Calls.Add("action1");
return string.Empty;
}

[Action("action2")]
public bool Action2()
public Task<string> Action2()
{
Calls.Add("action2");
return true;
return Task.FromResult(string.Empty);
}

[Action("action3")]
public Task Action3()
public ValueTask<string> Action6()
{
Calls.Add("action3");
return Task.CompletedTask;
}

[Action("action4")]
public Task<bool> Action4()
{
Calls.Add("action4");
return Task.FromResult(true);
}

[Action("action5")]
public ValueTask Action5()
{
Calls.Add("action5");
return ValueTask.CompletedTask;
}

[Action("action6")]
public ValueTask<bool> Action6()
{
Calls.Add("action6");
return ValueTask.FromResult(true);
return ValueTask.FromResult(string.Empty);
}
}

private sealed class DifferentParameterAttributesActions<TState> where TState : ITurnState<StateBase, StateBase, TempState>
private sealed class DifferentParameterAttributesActions<TState> where TState : TurnState
{
public List<object?[]> Calls { get; set; } = new List<object?[]>();

[Action("action1")]
public void Action1([ActionTurnContext] ITurnContext context, [ActionTurnState] TState state, [ActionEntities] object entities, [ActionName] string name)
public string Action1([ActionTurnContext] ITurnContext context, [ActionTurnState] TState state, [ActionParameters] object entities, [ActionName] string name)
{
Calls.Add(new[] { context, state, entities, name });
return string.Empty;
}

[Action("action2")]
public void Action2([ActionName] string name, [ActionEntities] object entities, [ActionTurnState] TState state, [ActionTurnContext] ITurnContext context)
public string Action2([ActionName] string name, [ActionParameters] object entities, [ActionTurnState] TState state, [ActionTurnContext] ITurnContext context)
{
Calls.Add(new[] { name, entities, state, context });
return string.Empty;
}

[Action("action3")]
public void Action3([ActionTurnContext] ITurnContext context, [ActionName] string name)
public string Action3([ActionTurnContext] ITurnContext context, [ActionName] string name)
{
Calls.Add(new object?[] { context, name });
return string.Empty;
}

[Action("action4")]
public void Action4([ActionTurnContext] ITurnContext context, ITurnContext myContext, int myInt)
public string Action4([ActionTurnContext] ITurnContext context, ITurnContext myContext, int myInt)
{
Calls.Add(new object?[] { context, myContext, myInt });
return string.Empty;
}

[Action("action5")]
public void Action5([ActionTurnState] TState state1, [ActionTurnState] TState state2, [ActionName] string name)
public string Action5([ActionTurnState] TState state1, [ActionTurnState] TState state2, [ActionName] string name)
{
Calls.Add(new object?[] { state1, state2, name });
return string.Empty;
}

[Action("action6")]
public void Action6()
public string Action6()
{
Calls.Add(new object?[] { });
return string.Empty;
}
}

private sealed class TestActions<TContext, TState, TEntities, TName>
{
[Action("action")]
public static void Action([ActionTurnContext] TContext _0, [ActionTurnState] TState _1, [ActionEntities] TEntities _2, [ActionName] TName _3) { }
public static string Action([ActionTurnContext] TContext _0, [ActionTurnState] TState _1, [ActionParameters] TEntities _2, [ActionName] TName _3)
{
return string.Empty;
}
}
}
}
Loading

0 comments on commit a20f871

Please sign in to comment.