Skip to content

Commit

Permalink
[C#] feat: Azure AI Search data source (#1411)
Browse files Browse the repository at this point in the history
## Linked issues

closes: #1410 (issue number)

## Details

* Azure AI Search data store 
* Indexer project to create/delete the required index to test the bot.


## 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: Corina <[email protected]>
  • Loading branch information
singhk97 and corinagum authored Mar 20, 2024
1 parent 6c7bfe8 commit 9829e90
Show file tree
Hide file tree
Showing 33 changed files with 1,665 additions and 1 deletion.
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,19 @@ env/.env.local
env/.env.staging
.env*
/dotnet/samples/NuGet.Config
/dotnet/samples/LocalPkg/
/dotnet/samples/LocalPkg/
/dotnet/samples/08.datasource.azureaisearch/bin/Debug/net6.0
/dotnet/samples/08.datasource.azureaisearch/obj
/dotnet/samples/08.datasource.azureaisearch/.vs
/dotnet/samples/08.datasource.azureaisearch/AzureAISearchBot/bin/Debug
/dotnet/samples/08.datasource.azureaisearch/AzureAISearchBot/obj
/dotnet/samples/08.datasource.azureaisearch/AzureAISearchBot/AzureAISearchBot.csproj.user
/dotnet/samples/08.datasource.azureaisearch/AzureAISearchBot/AzureAISearchBot.user
/dotnet/samples/08.datasource.azureaisearch/AzureAISearchIndexer/bin/Debug/net8.0
/dotnet/samples/08.datasource.azureaisearch/AzureAISearchIndexer/obj/Debug/net8.0
/dotnet/samples/AzureAISearchIndexer/obj
/dotnet/samples/08.datasource.azureaisearch/AzureAISearchIndexer/obj
/dotnet/samples/08.datasource.azureaisearch/AzureAISearchIndexer/appsettings.json
/dotnet/samples/08.datasource.azureaisearch/AzureAISearchBot/appsettings.Development.json
/dotnet/samples/08.datasource.azureaisearch/AzureAISearchBot/appsettings.json
/dotnet/samples/08.datasource.azureaisearch/AzureAISearchBot/appsettings.TestTool.json
31 changes: 31 additions & 0 deletions dotnet/samples/08.datasource.azureaisearch/AzureAISearchBot.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34511.98
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureAISearchBot", ".\AzureAISearchBot\AzureAISearchBot.csproj", "{C2964D35-6742-4DBF-9685-5DD5A01D8D82}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureAISearchIndexer", ".\AzureAISearchIndexer\AzureAISearchIndexer.csproj", "{2B95F57A-3475-418F-A3B0-54A9E0F0CFEF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C2964D35-6742-4DBF-9685-5DD5A01D8D82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2964D35-6742-4DBF-9685-5DD5A01D8D82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2964D35-6742-4DBF-9685-5DD5A01D8D82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2964D35-6742-4DBF-9685-5DD5A01D8D82}.Release|Any CPU.Build.0 = Release|Any CPU
{2B95F57A-3475-418F-A3B0-54A9E0F0CFEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B95F57A-3475-418F-A3B0-54A9E0F0CFEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B95F57A-3475-418F-A3B0-54A9E0F0CFEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B95F57A-3475-418F-A3B0-54A9E0F0CFEF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {30CCD595-AEBE-4CC2-B016-33E2EA023EAE}
EndGlobalSection
EndGlobal
115 changes: 115 additions & 0 deletions dotnet/samples/08.datasource.azureaisearch/AzureAISearchBot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
.zip

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
/**/lib
lib

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Teams Toolkit
env/.env.*.user
env/.env.local
appPackage/build
.deployment
devTools/
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.Bot.Builder;
using Microsoft.Teams.AI.AI.Action;
using Microsoft.Teams.AI.AI;
using System.Text.Json;

namespace AzureAISearchBot
{
public class ActionHandlers
{
[Action(AIConstants.FlaggedInputActionName)]
public async Task<string> OnFlaggedInput([ActionTurnContext] ITurnContext turnContext, [ActionParameters] Dictionary<string, object> entities)
{
string entitiesJsonString = JsonSerializer.Serialize(entities);
await turnContext.SendActivityAsync($"I'm sorry your message was flagged: {entitiesJsonString}");
return "";
}

[Action(AIConstants.FlaggedOutputActionName)]
public async Task<string> OnFlaggedOutput([ActionTurnContext] ITurnContext turnContext)
{
await turnContext.SendActivityAsync("I'm not allowed to talk about such things.");
return "";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Teams.AI;

namespace AzureAISearchBot
{
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");
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<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="Azure.Search.Documents" Version="11.6.0-beta.3" />
<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>
<ItemGroup>
<ProjectReference Include="..\AzureAISearchIndexer\AzureAISearchIndexer.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit 9829e90

Please sign in to comment.