-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C#] feat:
Azure OpenAI On Your Data
support (#1478)
## Linked issues closes: #1420 (issue number) ## Details * Added addtional data properties to `config.json` * Added `08.datasource.azureopenai` sample ## 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 --------- Co-authored-by: Alex Acebo <[email protected]>
- Loading branch information
Showing
31 changed files
with
994 additions
and
20 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
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
58 changes: 58 additions & 0 deletions
58
dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/MessageContext.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,58 @@ | ||
using Microsoft.Teams.AI.Utilities; | ||
|
||
namespace Microsoft.Teams.AI.AI.Models | ||
{ | ||
/// <summary> | ||
/// The message context. | ||
/// </summary> | ||
public class MessageContext | ||
{ | ||
/// <summary> | ||
/// Citations used in the message. | ||
/// </summary> | ||
public IList<Citation> Citations { get; } = new List<Citation>(); | ||
|
||
/// <summary> | ||
/// The intent of the message. | ||
/// </summary> | ||
public string Intent { get; set; } = string.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// Citations used in the message. | ||
/// </summary> | ||
public class Citation | ||
{ | ||
/// <summary> | ||
/// The content of the citation. | ||
/// </summary> | ||
public string Content { get; set; } | ||
|
||
/// <summary> | ||
/// The title of the citation. | ||
/// </summary> | ||
public string Title { get; set; } | ||
|
||
/// <summary> | ||
/// The URL of the citation. | ||
/// </summary> | ||
public string Url { get; set; } | ||
|
||
/// <summary> | ||
/// Constructs a citation. | ||
/// </summary> | ||
/// <param name="content">The content of the citation.</param> | ||
/// <param name="title">The title of the citation.</param> | ||
/// <param name="url">The url of the citation.</param> | ||
public Citation(string content, string title, string url) | ||
{ | ||
Verify.ParamNotNull(content); | ||
Verify.ParamNotNull(title); | ||
Verify.ParamNotNull(url); | ||
|
||
Content = content; | ||
Title = title; | ||
Url = url; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
AzureOpenAIBot/bin/Debug | ||
AzureOpenAIBot/obj | ||
AzureOpenAIBot.csproj.user | ||
AzureOpenAIBot.user | ||
appsettings.Development.json | ||
appsettings.json | ||
appsettings.TestTool.json | ||
.vs/ | ||
**/env/ | ||
bin/Debug/ | ||
obj/ | ||
appPackage/ |
26 changes: 26 additions & 0 deletions
26
dotnet/samples/08.datasource.azureopenai/AdapterWithErrorHandler.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,26 @@ | ||
using Microsoft.Bot.Builder.TraceExtensions; | ||
using Microsoft.Teams.AI; | ||
|
||
namespace AzureOpenAIBot | ||
{ | ||
public class AdapterWithErrorHandler : TeamsAdapter | ||
{ | ||
public AdapterWithErrorHandler(IConfiguration configuration, ILogger<TeamsAdapter> logger) | ||
: base(configuration, null, logger) | ||
{ | ||
OnTurnError = async (turnContext, exception) => | ||
{ | ||
// Log any leaked exception from the application. | ||
// NOTE: In production environment, you should consider logging this to | ||
// Azure Application Insights. Visit https://aka.ms/bottelemetry to see how | ||
// to add telemetry capture to your bot. | ||
logger.LogError(exception, $"[OnTurnError] unhandled error : {exception.Message}"); | ||
// Send a message to the user | ||
await turnContext.SendActivityAsync($"The bot encountered an unhandled error: {exception.Message}"); | ||
await turnContext.SendActivityAsync("To continue to run this bot, please fix the bot source code."); | ||
// Send a trace activity | ||
await turnContext.TraceActivityAsync("OnTurnError Trace", exception.Message, "https://www.botframework.com/schemas/error", "TurnError"); | ||
}; | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
dotnet/samples/08.datasource.azureopenai/AzureOpenAIBot.csproj
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,38 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectCapability Include="TeamsFx" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Bot.Builder" Version="4.21.1" /> | ||
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.21.1" /> | ||
<PackageReference Include="Microsoft.Bot.Connector" Version="4.21.1" /> | ||
<PackageReference Include="Microsoft.Teams.AI" Version="1.1.*" /> | ||
</ItemGroup> | ||
|
||
<!-- Exclude Teams Toolkit files from build output, but can still be viewed from Solution Explorer --> | ||
<ItemGroup> | ||
<Content Remove="appPackage/**/*" /> | ||
<None Include="appPackage/**/*" /> | ||
<None Include="env/**/*" /> | ||
<Content Remove="infra/**/*" /> | ||
<None Include="infra/**/*" /> | ||
</ItemGroup> | ||
|
||
<!-- Exclude local settings from publish --> | ||
<ItemGroup> | ||
<Content Remove="appsettings.Development.json" /> | ||
<Content Include="appsettings.Development.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<CopyToPublishDirectory>None</CopyToPublishDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.