-
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.
[C#] port: TeamsAttachmentDownloader, vision support...etc (#1723)
## Linked issues closes: #1011 #1182 (issue number) ## Details Implements the TeamsAttachmentDownloader and OpenAI/AOAI Vision model support #### Change details * Bumped `Azure.AI.OpenAI` to version `1.0.0-beta.17` * Implemented TeamsAttachmentDownloader * Auxilliary changes in the `Application/` and `AI/` code. * Implemented and tested CardGazer sample. ##### Breaking Change * `ChatMessage.Content` is changed from `string?` to `object?` since it can hold a `string` or `IEnumerable<MessageContentParts>` ## 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
Showing
68 changed files
with
1,810 additions
and
63 deletions.
There are no files selected for viewing
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
32 changes: 32 additions & 0 deletions
32
dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI.Tests/AITests/ChatMessageTests.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,32 @@ | ||
using Microsoft.Teams.AI.AI.Models; | ||
|
||
namespace Microsoft.Teams.AI.Tests.AITests | ||
{ | ||
public class ChatMessageTests | ||
{ | ||
[Fact] | ||
public void Test_Get_Content() | ||
{ | ||
// Arrange | ||
ChatMessage msg = new(ChatRole.Assistant); | ||
msg.Content = "test"; | ||
|
||
// Act | ||
var content = msg.GetContent<string>(); | ||
|
||
// Assert | ||
Assert.Equal("test", content); | ||
} | ||
|
||
[Fact] | ||
public void Test_Get_Content_TypeMismatch_ThrowsException() | ||
{ | ||
// Arrange | ||
ChatMessage msg = new(ChatRole.Assistant); | ||
msg.Content = "test"; | ||
|
||
// Act & Assert | ||
Assert.Throws<InvalidCastException>(() => msg.GetContent<bool>()); | ||
} | ||
} | ||
} |
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
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
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
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
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
51 changes: 51 additions & 0 deletions
51
...icrosoft.TeamsAI.Tests/AITests/PromptsTests/SectionsTests/UserInputMessageSectionTests.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,51 @@ | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Teams.AI.AI.Models; | ||
using Microsoft.Teams.AI.AI.Prompts.Sections; | ||
using Microsoft.Teams.AI.AI.Prompts; | ||
using Microsoft.Teams.AI.AI.Tokenizers; | ||
using Microsoft.Teams.AI.State; | ||
using Moq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Teams.AI.Application; | ||
using static System.Net.Mime.MediaTypeNames; | ||
|
||
namespace Microsoft.Teams.AI.Tests.AITests.PromptsTests.SectionsTests | ||
{ | ||
public class UserInputMessageSectionTest | ||
{ | ||
[Fact] | ||
public async void Test_RenderAsMessagesAsync_ShoulderRender() | ||
{ | ||
// Arrange | ||
UserInputMessageSection section = new(); | ||
Mock<ITurnContext> context = new(); | ||
MemoryFork memory = new(); | ||
GPTTokenizer tokenizer = new(); | ||
PromptManager manager = new(); | ||
|
||
// Act | ||
memory.SetValue("input", "hi"); | ||
|
||
memory.SetValue("inputFiles", new List<InputFile>() | ||
{ | ||
new(BinaryData.FromString("testData"), "image/png") | ||
}); | ||
|
||
// Assert | ||
RenderedPromptSection<List<ChatMessage>> rendered = await section.RenderAsMessagesAsync(context.Object, memory, manager, tokenizer, 200); | ||
var messageContentParts = rendered.Output[0].GetContent<List<MessageContentParts>>(); | ||
|
||
Assert.Equal("hi", ((TextContentPart)messageContentParts[0]).Text); | ||
|
||
// the base64 string is an encoding of "hi" | ||
var imageUrl = $"data:image/png;base64,dGVzdERhdGE="; | ||
Assert.Equal(imageUrl, ((ImageContentPart)messageContentParts[1]).ImageUrl); | ||
|
||
Assert.Equal(86, rendered.Length); | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.