-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1297 from Microsoft/johtaylo/qna-update
updated qna bot
- Loading branch information
Showing
15 changed files
with
165 additions
and
556 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
samples/csharp_dotnetcore/11.qnamaker/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,24 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.Bot.Builder.Integration.AspNet.Core; | ||
using Microsoft.Bot.Connector.Authentication; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.BotBuilderSamples | ||
{ | ||
public class AdapterWithErrorHandler : BotFrameworkHttpAdapter | ||
{ | ||
public AdapterWithErrorHandler(ICredentialProvider credentialProvider, ILogger<BotFrameworkHttpAdapter> logger) | ||
: base(credentialProvider) | ||
{ | ||
// Enable logging at the adapter level using OnTurnError. | ||
OnTurnError = async (turnContext, exception) => | ||
{ | ||
logger.LogError($"Exception caught : {exception}"); | ||
await turnContext.SendActivityAsync("Sorry, it looks like something went wrong."); | ||
await turnContext.SendActivityAsync("To run this sample make sure you have the QnA model deployed."); | ||
}; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Builder.AI.QnA; | ||
using Microsoft.Bot.Schema; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.BotBuilderSamples | ||
{ | ||
public class QnABot : ActivityHandler | ||
{ | ||
private IConfiguration _configuration; | ||
private ILogger<QnABot> _logger; | ||
|
||
public QnABot(IConfiguration configuration, ILogger<QnABot> logger) | ||
{ | ||
_configuration = configuration; | ||
_logger = logger; | ||
} | ||
|
||
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken) | ||
{ | ||
var qnaMaker = new QnAMaker(new QnAMakerEndpoint | ||
{ | ||
KnowledgeBaseId = _configuration["QnA-sample-qna-kbId"], | ||
EndpointKey = _configuration["QnA-sample-qna-endpointKey"], | ||
Host = _configuration["QnA-sample-qna-hostname"] | ||
}); | ||
|
||
_logger.LogInformation("Calling QnA Maker"); | ||
|
||
// The actual call to the QnA Maker service. | ||
var response = await qnaMaker.GetAnswersAsync(turnContext); | ||
if (response != null && response.Length > 0) | ||
{ | ||
await turnContext.SendActivityAsync(MessageFactory.Text(response[0].Answer), cancellationToken); | ||
} | ||
else | ||
{ | ||
await turnContext.SendActivityAsync(MessageFactory.Text("No QnA Maker answers were found."), cancellationToken); | ||
} | ||
} | ||
} | ||
} |
62 changes: 0 additions & 62 deletions
62
samples/csharp_dotnetcore/11.qnamaker/CognitiveModels/sample.qna
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
samples/csharp_dotnetcore/11.qnamaker/ConfigurationCredentialProvider.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,16 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.Bot.Connector.Authentication; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Microsoft.BotBuilderSamples | ||
{ | ||
public class ConfigurationCredentialProvider : SimpleCredentialProvider | ||
{ | ||
public ConfigurationCredentialProvider(IConfiguration configuration) | ||
: base(configuration["Microsoft-BotFramework-AppId"], configuration["Microsoft-BotFramework-AppPassword"]) | ||
{ | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
samples/csharp_dotnetcore/11.qnamaker/Controllers/BotController.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,35 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Builder.Integration.AspNet.Core; | ||
|
||
namespace Microsoft.BotBuilderSamples | ||
{ | ||
// This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot | ||
// implementation at runtime. Multiple different IBot implementations running at different endpoints can be | ||
// achieved by specifying a more specific type for the bot constructor argument. | ||
[Route("api/messages")] | ||
[ApiController] | ||
public class BotController : ControllerBase | ||
{ | ||
private readonly IBotFrameworkHttpAdapter _adapter; | ||
private readonly IBot _bot; | ||
|
||
public BotController(IBotFrameworkHttpAdapter adapter, IBot bot) | ||
{ | ||
_adapter = adapter; | ||
_bot = bot; | ||
} | ||
|
||
[HttpPost] | ||
public async Task PostAsync() | ||
{ | ||
// Delegate the processing of the HTTP POST to the adapter. | ||
// The adapter will invoke the bot. | ||
await _adapter.ProcessAsync(Request, Response, _bot); | ||
} | ||
} | ||
} |
62 changes: 0 additions & 62 deletions
62
samples/csharp_dotnetcore/11.qnamaker/DeploymentScripts/MsbotClone/34.qna
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
samples/csharp_dotnetcore/11.qnamaker/DeploymentScripts/MsbotClone/bot.recipe
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,29 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<CodeAnalysisRuleSet></CodeAnalysisRuleSet> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Update="*.bot"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" /> | ||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" /> | ||
<PackageReference Include="Microsoft.Bot.Builder.AI.QnA" Version="4.2.2" /> | ||
<PackageReference Include="Microsoft.Bot.Builder" Version="4.2.2" /> | ||
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.2.2" /> | ||
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.2.2" /> | ||
<PackageReference Include="AsyncUsageAnalyzers" Version="1.0.0-alpha003" PrivateAssets="all" /> | ||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta008" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<WCFMetadata Include="Connected Services" /> | ||
<PackageReference Include="Microsoft.AspNetCore.App" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" /> | ||
<PackageReference Include="Microsoft.Bot.Builder.AI.QnA" Version="4.3.1" /> | ||
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.3.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.