Skip to content

Commit 83c08c7

Browse files
authored
Merge branch 'PYTHON' into lilyydu/augmentations
2 parents 57fe0e5 + 1208dbb commit 83c08c7

File tree

179 files changed

+6454
-797
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+6454
-797
lines changed

.github/workflows/coverage.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
parallel: true
8484
files: ${{ env.SOLUTION_DIR }}TestResults/coverage/lcov.info
8585
- name: Upload Tests
86-
uses: actions/upload-artifact@694cdabd8bdb0f10b2cea11669e1bf5453eed0a6 # v4.2.0
86+
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
8787
with:
8888
name: testresults-dotnet-${{ env.dotnet-version }}
8989
path: ${{ env.SOLUTION_DIR }}TestResults

.github/workflows/dotnet-build-test-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
reporttypes: 'HtmlInline;lcov'
5151
toolpath: ${{ env.SOLUTION_DIR }}report-generator-tool
5252
- name: Upload Tests
53-
uses: actions/upload-artifact@694cdabd8bdb0f10b2cea11669e1bf5453eed0a6 # v4.2.0
53+
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
5454
with:
5555
name: testresults-dotnet-${{ matrix.dotnet-version }}
5656
path: ${{ env.SOLUTION_DIR }}TestResults

.github/workflows/dotnet-codeql.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- name: Checkout
4040
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
4141
- name: Initialize CodeQL
42-
uses: github/codeql-action/init@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
42+
uses: github/codeql-action/init@b7bf0a3ed3ecfa44160715d7c442788f65f0f923 # v3.23.2
4343
with:
4444
languages: csharp
4545
- name: Setup .NET
@@ -50,6 +50,6 @@ jobs:
5050
working-directory: dotnet/packages/Microsoft.TeamsAI/
5151
run: dotnet build Microsoft.Teams.AI.sln --configuration Release
5252
- name: Perform CodeQL Analysis
53-
uses: github/codeql-action/analyze@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
53+
uses: github/codeql-action/analyze@b7bf0a3ed3ecfa44160715d7c442788f65f0f923 # v3.23.2
5454
with:
5555
category: "/language:csharp"

.github/workflows/dotnet-publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- name: Publish
4545
run: dotnet nuget push *.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/microsoft/index.json --skip-duplicate --no-symbols
4646
- name: Upload
47-
uses: actions/upload-artifact@694cdabd8bdb0f10b2cea11669e1bf5453eed0a6 # v4.2.0
47+
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
4848
with:
4949
name: nupkg-dotnet-${{ matrix.dotnet-version }}
5050
path: dotnet/packages/Microsoft.TeamsAI/*.nupkg

.github/workflows/js-codeql.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ jobs:
3838
- name: Checkout
3939
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
4040
- name: Initialize CodeQL
41-
uses: github/codeql-action/init@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
41+
uses: github/codeql-action/init@b7bf0a3ed3ecfa44160715d7c442788f65f0f923 # v3.23.2
4242
with:
4343
languages: javascript
4444
- name: Perform CodeQL Analysis
45-
uses: github/codeql-action/analyze@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
45+
uses: github/codeql-action/analyze@b7bf0a3ed3ecfa44160715d7c442788f65f0f923 # v3.23.2
4646
with:
4747
category: "/language:javascript"

.github/workflows/scorecards.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ jobs:
5858
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
5959
# format to the repository Actions tab.
6060
- name: "Upload artifact"
61-
uses: actions/upload-artifact@694cdabd8bdb0f10b2cea11669e1bf5453eed0a6 # v4.2.0
61+
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
6262
with:
6363
name: SARIF file
6464
path: results.sarif
6565
retention-days: 5
6666

6767
# Upload the results to GitHub's code scanning dashboard.
6868
- name: "Upload to code-scanning"
69-
uses: github/codeql-action/upload-sarif@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
69+
uses: github/codeql-action/upload-sarif@b7bf0a3ed3ecfa44160715d7c442788f65f0f923 # v3.23.2
7070
with:
7171
sarif_file: results.sarif

dotnet/packages/.editorconfig

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ charset = utf-8-bom
4545
# Organize usings
4646
dotnet_sort_system_directives_first = true:warning
4747
# this. preferences
48-
dotnet_style_qualification_for_field = true:warning
49-
dotnet_style_qualification_for_property = true:warning
50-
dotnet_style_qualification_for_method = true:warning
51-
dotnet_style_qualification_for_event = true:warning
48+
dotnet_style_qualification_for_field = true:suggestion
49+
dotnet_style_qualification_for_property = true:suggestion
50+
dotnet_style_qualification_for_method = true:suggestion
51+
dotnet_style_qualification_for_event = true:suggestion
5252
# Language keywords vs BCL types preferences
5353
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
5454
dotnet_style_predefined_type_for_member_access = true:warning
@@ -61,17 +61,17 @@ dotnet_style_parentheses_in_other_operators = never_if_unnecessary:warning
6161
dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning
6262
dotnet_style_readonly_field = true:warning
6363
# Expression-level preferences
64-
dotnet_style_object_initializer = true:warning
64+
dotnet_style_object_initializer = true:suggestion
6565
dotnet_style_collection_initializer = true:warning
6666
dotnet_style_explicit_tuple_names = true:warning
6767
dotnet_style_null_propagation = true:warning
68-
dotnet_style_coalesce_expression = true:warning
68+
dotnet_style_coalesce_expression = true:suggestion
6969
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
7070
dotnet_style_prefer_inferred_tuple_names = true:warning
7171
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
7272
dotnet_style_prefer_auto_properties = true:warning
7373
dotnet_style_prefer_conditional_expression_over_assignment = true:warning
74-
dotnet_style_prefer_conditional_expression_over_return = true:warning
74+
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
7575
dotnet_style_prefer_simplified_interpolation = true:warning
7676
dotnet_style_operator_placement_when_wrapping = beginning_of_line
7777
dotnet_style_prefer_simplified_boolean_expressions = true:warning
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Microsoft.Teams.AI.AI.Models;
2+
using Microsoft.Teams.AI.Exceptions;
3+
4+
namespace Microsoft.Teams.AI.Tests.AITests.Models
5+
{
6+
public class AzureSdkChatMessageExtensions
7+
{
8+
[Fact]
9+
public void Test_ChatCompletionsToolCall_ToFunctionToolCall()
10+
{
11+
// Arrange
12+
var functionToolCall = new Azure.AI.OpenAI.ChatCompletionsFunctionToolCall("test-id", "test-name", "test-arg1");
13+
14+
// Act
15+
var azureSdkFunctionToolCall = functionToolCall.ToChatCompletionsToolCall();
16+
17+
// Assert
18+
var toolCall = azureSdkFunctionToolCall as ChatCompletionsFunctionToolCall;
19+
Assert.NotNull(toolCall);
20+
Assert.Equal("test-id", toolCall.Id);
21+
Assert.Equal("test-name", toolCall.Name);
22+
Assert.Equal("test-arg1", toolCall.Arguments);
23+
}
24+
25+
[Fact]
26+
public void Test_ChatCompletionsToolCall_InvalidToolType()
27+
{
28+
// Arrange
29+
var functionToolCall = new InvalidToolCall();
30+
31+
// Act
32+
var ex = Assert.Throws<TeamsAIException>(() => functionToolCall.ToChatCompletionsToolCall());
33+
34+
// Assert
35+
Assert.Equal($"Invalid ChatCompletionsToolCall type: {nameof(InvalidToolCall)}", ex.Message);
36+
}
37+
38+
private class InvalidToolCall : Azure.AI.OpenAI.ChatCompletionsToolCall
39+
{
40+
public InvalidToolCall() : base("test-id")
41+
{
42+
}
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,175 @@
1-
using Microsoft.Teams.AI.AI.Models;
1+
using Azure.AI.OpenAI;
2+
using Microsoft.Teams.AI.AI.Models;
3+
using Microsoft.Teams.AI.Exceptions;
24

35
namespace Microsoft.Teams.AI.Tests.AITests.Models
46
{
57
public class ChatMessageExtensionsTests
68
{
79
[Fact]
8-
public void Test_ToAzureSdkChatMessage()
10+
public void Test_InvalidRole_ToAzureSdkChatMessage()
911
{
1012
// Arrange
11-
var chatMessage = new ChatMessage(ChatRole.User)
13+
var chatMessage = new ChatMessage(new AI.Models.ChatRole("InvalidRole"));
14+
15+
// Act
16+
var ex = Assert.Throws<TeamsAIException>(() => chatMessage.ToChatRequestMessage());
17+
18+
// Assert
19+
Assert.Equal($"Invalid chat message role: InvalidRole", ex.Message);
20+
}
21+
22+
[Fact]
23+
public void Test_UserRole_ToAzureSdkChatMessage()
24+
{
25+
// Arrange
26+
var chatMessage = new ChatMessage(AI.Models.ChatRole.User)
27+
{
28+
Content = "test-content",
29+
Name = "author"
30+
};
31+
32+
// Act
33+
var result = chatMessage.ToChatRequestMessage();
34+
35+
// Assert
36+
Assert.Equal(Azure.AI.OpenAI.ChatRole.User, result.Role);
37+
Assert.Equal(typeof(ChatRequestUserMessage), result.GetType());
38+
Assert.Equal("test-content", ((ChatRequestUserMessage)result).Content);
39+
Assert.Equal("author", ((ChatRequestUserMessage)result).Name);
40+
}
41+
42+
[Fact]
43+
public void Test_AssistantRole_ToAzureSdkChatMessage()
44+
{
45+
// Arrange
46+
var functionCall = new AI.Models.FunctionCall("test-name", "test-arg1");
47+
var chatMessage = new ChatMessage(AI.Models.ChatRole.Assistant)
1248
{
49+
Content = "test-content",
1350
Name = "test-name",
51+
FunctionCall = functionCall,
52+
ToolCalls = new List<AI.Models.ChatCompletionsToolCall>()
53+
{
54+
new AI.Models.ChatCompletionsFunctionToolCall("test-id", "test-tool-name", "test-tool-arg1")
55+
}
56+
};
57+
58+
// Act
59+
var result = chatMessage.ToChatRequestMessage();
60+
61+
// Assert
62+
Assert.Equal(Azure.AI.OpenAI.ChatRole.Assistant, result.Role);
63+
ChatRequestAssistantMessage? message = result as ChatRequestAssistantMessage;
64+
Assert.NotNull(message);
65+
Assert.Equal("test-content", message.Content);
66+
Assert.Equal("test-name", message.Name);
67+
Assert.Equal("test-arg1", message.FunctionCall.Arguments);
68+
Assert.Equal("test-name", message.FunctionCall.Name);
69+
70+
Assert.Equal(1, message.ToolCalls.Count);
71+
Azure.AI.OpenAI.ChatCompletionsFunctionToolCall? toolCall = message.ToolCalls[0] as Azure.AI.OpenAI.ChatCompletionsFunctionToolCall;
72+
Assert.NotNull(toolCall);
73+
Assert.Equal("test-id", toolCall.Id);
74+
Assert.Equal("test-tool-name", toolCall.Name);
75+
Assert.Equal("test-tool-arg1", toolCall.Arguments);
76+
}
77+
78+
[Fact]
79+
public void Test_SystemRole_ToAzureSdkChatMessage()
80+
{
81+
// Arrange
82+
var chatMessage = new ChatMessage(AI.Models.ChatRole.System)
83+
{
84+
Content = "test-content",
85+
Name = "author"
86+
};
87+
88+
// Act
89+
var result = chatMessage.ToChatRequestMessage();
90+
91+
// Assert
92+
Assert.Equal(Azure.AI.OpenAI.ChatRole.System, result.Role);
93+
Assert.Equal(typeof(ChatRequestSystemMessage), result.GetType());
94+
Assert.Equal("test-content", ((ChatRequestSystemMessage)result).Content);
95+
Assert.Equal("author", ((ChatRequestSystemMessage)result).Name);
96+
}
97+
98+
[Fact]
99+
public void Test_FunctionRole_ToAzureSdkChatMessage()
100+
{
101+
// Arrange
102+
var chatMessage = new ChatMessage(AI.Models.ChatRole.Function)
103+
{
104+
Content = "test-content",
105+
Name = "function-name"
106+
};
107+
108+
// Act
109+
var result = chatMessage.ToChatRequestMessage();
110+
111+
// Assert
112+
Assert.Equal(Azure.AI.OpenAI.ChatRole.Function, result.Role);
113+
Assert.Equal(typeof(ChatRequestFunctionMessage), result.GetType());
114+
Assert.Equal("test-content", ((ChatRequestFunctionMessage)result).Content);
115+
}
116+
117+
[Fact]
118+
public void Test_ToolRole_ToAzureSdkChatMessage()
119+
{
120+
// Arrange
121+
var chatMessage = new ChatMessage(AI.Models.ChatRole.Tool)
122+
{
14123
Content = "test-content",
124+
Name = "tool-name",
125+
ToolCallId = "tool-call-id"
15126
};
16127

17128
// Act
18-
var result1 = chatMessage.ToAzureSdkChatMessage();
19-
chatMessage.FunctionCall = new FunctionCall("test-name", "test-args");
20-
var result2 = chatMessage.ToAzureSdkChatMessage();
129+
var result = chatMessage.ToChatRequestMessage();
130+
131+
// Assert
132+
Assert.Equal(Azure.AI.OpenAI.ChatRole.Tool, result.Role);
133+
Assert.Equal(typeof(ChatRequestToolMessage), result.GetType());
134+
Assert.Equal("test-content", ((ChatRequestToolMessage)result).Content);
135+
Assert.Equal("tool-call-id", ((ChatRequestToolMessage)result).ToolCallId);
136+
}
137+
138+
[Fact]
139+
public void Test_ChatCompletionsToolCall_ToFunctionToolCall()
140+
{
141+
// Arrange
142+
var functionToolCall = new AI.Models.ChatCompletionsFunctionToolCall("test-id", "test-name", "test-arg1");
143+
144+
// Act
145+
var azureSdkFunctionToolCall = functionToolCall.ToAzureSdkChatCompletionsToolCall();
146+
147+
// Assert
148+
var toolCall = azureSdkFunctionToolCall as Azure.AI.OpenAI.ChatCompletionsFunctionToolCall;
149+
Assert.NotNull(toolCall);
150+
Assert.Equal("test-id", toolCall.Id);
151+
Assert.Equal("test-name", toolCall.Name);
152+
Assert.Equal("test-arg1", toolCall.Arguments);
153+
}
154+
155+
[Fact]
156+
public void Test_ChatCompletionsToolCall_InvalidToolType()
157+
{
158+
// Arrange
159+
var functionToolCall = new InvalidToolCall();
160+
161+
// Act
162+
var ex = Assert.Throws<TeamsAIException>(() => functionToolCall.ToAzureSdkChatCompletionsToolCall());
21163

22164
// Assert
23-
Assert.Equal(Azure.AI.OpenAI.ChatRole.User, result1.Role);
24-
Assert.Equal("test-name", result1.Name);
25-
Assert.Equal("test-content", result1.Content);
26-
Assert.Null(result1.FunctionCall);
27-
Assert.Equal("test-name", result2.FunctionCall.Name);
28-
Assert.Equal("test-args", result2.FunctionCall.Arguments);
165+
Assert.Equal("Invalid tool type: invalidToolType", ex.Message);
166+
}
167+
168+
private class InvalidToolCall : AI.Models.ChatCompletionsToolCall
169+
{
170+
public InvalidToolCall() : base("invalidToolType", "test-id")
171+
{
172+
}
29173
}
30174
}
31175
}

0 commit comments

Comments
 (0)